Posted By

sgraber on 08/22/08


Tagged

google ip longitude latitude googlemaps


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

not_skeletor
elightbo
carlosabargues


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


 / Published in: JavaScript
 

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

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.

  1. if (GBrowserIsCompatible()) {
  2. var map = new google.maps.Map2(document.getElementById("my-googlemap"));
  3. if (google.loader.ClientLocation &&
  4. google.loader.ClientLocation.address.country_code == "US" &&
  5. google.loader.ClientLocation.address.region) {
  6. // geo locate was successful and user is in the states
  7. map.setCenter(
  8. new google.maps.LatLng(google.loader.ClientLocation.latitude,
  9. google.loader.ClientLocation.longitude
  10. ), 8
  11. );
  12. // do the rest of your map stuff here
  13. }
  14. }

Report this snippet  

You need to login to post a comment.