How to download the Google ClientLocation API without loading the entire Google Maps API?

All I want to do is find out the IP address of the person so that I can change the geocode to find out their latitude and longitude from which they are browsing my website.

I can do this using the Google ClientLocation API , but I don’t understand if I need to load the huge Google Map structure in order to use it.

Can I just use the ClientLocation API without loading all Google Maps? If so, how?

+4
source share
2 answers

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

<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> 

Available properties

  • 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
+12
source
 <html> <head> <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script> <br>Country Name: <script language="JavaScript">document.write(geoip_country_name());</script> <br>City: <script language="JavaScript">document.write(geoip_city());</script> <br>Latitude: <script language="JavaScript">document.write(geoip_latitude());</script> <br>Longitude: <script language="JavaScript">document.write(geoip_longitude());</script> </head> <body> Hope this will be useful for you </body> </html> 
-1
source

Source: https://habr.com/ru/post/1315475/


All Articles