/ Published in: JavaScript
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 } }
URL: http://code.google.com/apis/ajax/documentation/#ClientLocation