views:

156

answers:

1

All I want to do is find out the person IP address so that I can reverse geocode it to find out their latitude and longitude from which they are viewing my web site from.

I can do that using Google ClientLocation API but it's unclear to me if I have to load the huge Google Map framework just to use it.

Is it possible to simply use the ClientLocation API without having to load all of Google Maps? If so, how?

+1  A: 

Yes, you only need to use the ClientLocation object in the google.loader namespace so you need not reference the maps api or anything else. For example.

<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
  alert(google.loader.ClientLocation.address.city);
} else {
  alert("Not found");
}
</script>

The properties available are

  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.city
  • google.loader.ClientLocation.address.country
  • google.loader.ClientLocation.address.country_code
  • google.loader.ClientLocation.address.region
Fraser