Google Geocode via AJAX

I was looking for a quick way to copy and paste an address and get its longitude and latitude, so obviously I looked to Google maps for the answer.
If you have a Google map instantiated you can use it to geocode of an address, with the GClientGeocoder class, but what if you don’t want a map at all?
Of course there is an HTTP API to do it, which seemed a bit more like what I needed.
Here’s a pretty simple class that will make an AJAX request to the Google Geocode API and return the address and longitude and latitude in a standard object, rather than the hierarchical mess that the API itself returns.

function GoogleGeocode(apiKey) {
    this.apiKey = apiKey;
    this.geocode = function(address, callbackFunction) {
        jQuery.ajax({
            dataType: 'jsonp',
            url: 'http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false'
                    + '&key=' + this.apiKey + '&q=' + address,
            cache: false,
            success: function(data){
                if(data.Status.code==200) {
                    var result = {};
                    var ad = data.Placemark[0].AddressDetails.Country.AdministrativeArea;
                    result.streetAddress = ad.Locality.Thoroughfare && ad.Locality.Thoroughfare.ThoroughfareName ? ad.Locality.Thoroughfare.ThoroughfareName : '';
                    result.city = ad.Locality && ad.Locality.LocalityName ? ad.Locality.LocalityName : '';
                    result.state = ad && ad.AdministrativeAreaName ? ad.AdministrativeAreaName : '';
                    result.zip = ad.Locality.PostalCode && ad.Locality.PostalCode.PostalCodeNumber ? ad.Locality.PostalCode.PostalCodeNumber : '';
                    result.longitude = data.Placemark[0].Point.coordinates[0];
                    result.latitude = data.Placemark[0].Point.coordinates[1];
                    callbackFunction(result);
                } else {
                    callbackFunction(null);
                }
            }
          });
    };
}

As you should have noticed, it uses the jQuery javascript framework. The key piece of information in the class above is dataType: ‘jsonp’ which allows you to get JSON data from another domain, without triggering browser anti-XSS mechanisms.
Below is a simple usage example of the GoogleGeocode class.

var g = new GoogleGeocode('__your_google_api_key__');
var address = jQuery('#address').val();
g.geocode(address, function(data) {
    if(data != null) {
        alert("Street Address: " + data.streetAddress);
    } else {
        alert('ERROR! Unable to geocode address');
    }
});

  GoogleGeocode.js (1.5 KiB, 206 hits)

ActionScript Clock

As I’ve been looking at the different isometric stuff out there, I noticed a lot them are developed using Flash, so I thought I’d see what I can do. After a little messing about, several CS4 crashes and redos, I came up with this super terrific clock. It’s entirely written in ActionScript 3.0. All the (lame) graphics are generated with AS3.

Get Adobe Flash player

Isometric Pixeling – attempt #1

The “Bavaria Project” has taken a bit of a turn as far as the “visualization” is concerned. The new direction is towards an isometric variant of the engine we’re building for the “Gruthwal Project”.

This is all very much along the lines of sprites on the Commodore 64, so it wasn’t a huge stretch, except for the ability to use, my arch-enemy, colors.

I don’t think these came too bad for my first try. Much thanks to Rhys Davies and his tutorial: http://www.gotoandplay.it/_articles/2004/10/tcgtipa_p06.php

isometric people 1