Loading...

Google Maps : A Has No Properties

February 12, 2008 5 Comments Tagged as: google javascript mashups

I've been playing with creating a framework for easy mashups, starting with a little Yahoo! Pipes, and the using the data generated with other web services. One of these services was Google Maps. I went out and got my Maps API developer key and started hacking. After doing a few good little tests, I got to what I really wanted to try out: a mashup that'll help my wife and I find a new apartment by taking all the craigslist postings, pare it down to the number of bedrooms we need, the fact that we have a puppy that needs a yard, the area that we want to live, and post all the good matches to a Google map.

After I got the whole map set up, I found that Firebug was showing a javascript error 'a has no properties' There are tons of people asking the question, and the answers aren't quite as plentiful. In fact, most people recommended switching the API version from 2 to 2.s (whatever that means). All that did was get me a 'has no properties' for a different variable. My code looked like this (ignore the Django markup):

    <script type="text/javascript">
    //<![CDATA[
    
    function loadpoints() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.enableDragging();
        map.enableScrollWheelZoom();
        map.setCenter(new GLatLng({{lat}}, {{lon}}), 11);

        {% for location in locations %}
        {% if location.geo_long %}
        point = new GLatLng({{location.geo_lat}}, {{location.geo_long}});
        marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          var content = '<a href="{{location.link}}">{{location.title}}</a>';
          marker.openInfoWindowHtml(content);
        });
        map.addOverlay(marker);
      {% endif %}
      {% endfor %}
      }
    }
    //]]>
    </script>

I went through and commented out lines of javascript a bit at a time. I eventually found the issue, but it was quite a pain, and quite undocumented. The issue is this: I created my map, add some controls, set the center of the map to a GLatLng, and then started adding markers. Well, apparently, the first thing that needs to be done to a map is to set the center of the map. I couldn't find any documentation to reflect that, but it's the only way my mashup would work. So now, my code looks like this:

    <script type="text/javascript">
    //<![CDATA[
    
    function loadpoints() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng({{lat}}, {{lon}}), 11);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.enableDragging();
        map.enableScrollWheelZoom();

        {% for location in locations %}
        {% if location.geo_long %}
        point = new GLatLng({{location.geo_lat}}, {{location.geo_long}});
        marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          var content = '<a href="{{location.link}}">{{location.title}}</a>';
          marker.openInfoWindowHtml(content);
        });
        map.addOverlay(marker);
      {% endif %}
      {% endfor %}
      }
    }
    //]]>
    </script>

After looking through the documentation, it appears that the GMap2 constructor could take a opts.center option on instantiation, but it's not completely clear, and I'm far too lazy to actually try it out. Regardless, my rental mashup is working now, and I've got enough information to start working on my mashup framework, so that's all the information I need.

Ok, Android -- First Impressions of Google's New Platform

Since there was a Google (and before it was more than a search engine), I've wanted to be employed there. Alas, I certainly am not the best of the best, and probably would settle for someone to call me a mediocre developer (for now). I'm always so fascinated at some of the things Google does, so when Google released their Android SDK yesterday, I jumped at the chance to install it and play around.

First thing I took noticed is the Java. I'm not really a Java guy, and haven't touched it much since I was in school. However, for some reason, this time around, it felt better. Maybe it's because of my deeper understanding of object oriented programming now, or my love for python, but it was actually quite fun to be writing Java code. It required I install eclipse, which, from apt, was 100+ MB of packages, but it looked easier to do with Eclipse than without Eclipse.

I went through their documentation, installing the SDK and Eclipse plugin, and immediately went to the "Hello Android" application. I learn better by diving in and asking my own questions rather than looking at tons of sample code. This whole time, I found some features in Eclipse that I actually liked as well. While the code was simple, it was enough to make me hungry for more.

The best part of this whole process was compiling. Using the Eclipse Android plugin was a breeze (read: EASY BUILD MANAGEMENT!) After compiling the app and running it, I got a pretty little window pop up with a software phone, complete with pushable buttons. The phone's buttons resemble my Samsung Blackjack, but something tells me an Android-based phone will be so much more fun.

I ran into a little snag, however. The emulated phone wasn't running my app. It was just defaulting to the standard Android interface. This was frustrating. It seemed that no matter how I wrote the code, it just wouldn't run what I wrote. A quick hop over to the Android Google Group got me pointed in the right direction. The Android Debugger seemed to be getting in the way. I killed the process and ran my application again. Voila! I got the image you now see above you!

Having dabbled in J2ME, I must say that this is quite a step up for the mobile world. In fact, it's so easy that I'll probably start churning out little apps before the week is out! Great job you Googlees!

Edit: After digging down through documentation and dabbling some more in Android, I've discovered a few things of interest. First, the virtual machine running Android is not J2ME at all, but Google's Dalvik Virtual Machine. There is an entire media library set that supports H.264, AAC, and mpeg-4. That's actually a pretty wide range of media types. The last thing I was rather excited about is the data storage library, which is SQLite. It's constructed in a manner that allows all applications to interface with the SQLite database. My one fear is that the filesystem will turn out like the filesystem on the old Palm OS, where the entire thing was a database. It was kinda ugly...

29 Nov UPDATE An article was posted on LinuxInsider.com detailing the reasons why Android will change the market. I felt that when I started with Android, I still feel that now. Even if it fails miserably, Google's money went into making other businesses sit up and take notice of a platform that eases development.