Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load Google ClientLocation API without loading the whole Google Maps API?

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?

like image 951
SarahBee Avatar asked Dec 22 '22 01:12

SarahBee


1 Answers

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
like image 180
Fraser Avatar answered Dec 26 '22 10:12

Fraser