Return to Snippet

Revision: 7940
at August 22, 2008 23:49 by sgraber


Initial Code
if (GBrowserIsCompatible()) {
    var map = new google.maps.Map2(document.getElementById("my-googlemap"));
    if (google.loader.ClientLocation &&
        google.loader.ClientLocation.address.country_code == "US" &&
        google.loader.ClientLocation.address.region) {
        // geo locate was successful and user is in the states
        map.setCenter(
            new google.maps.LatLng(google.loader.ClientLocation.latitude,
                                   google.loader.ClientLocation.longitude
                                   ), 8
            );
        // do the rest of your map stuff here
    }
}

Initial URL
http://code.google.com/apis/ajax/documentation/#ClientLocation

Initial Description
Set the center of the map on the person's location based on IP address.  In this case the user is required to be in the USA.

Initial Title
google.loader.ClientLocation to get a person's lat/long using their IP address

Initial Tags
google, ip

Initial Language
JavaScript