Geolocation without a hint

I know about the HTML5 method for creating geolocation, but the caveat is that it should ask the user for permission.

navigator.geolocation.getCurrentPosition 

This becomes especially annoying when I would like to geolocate right on my home page to serve customized content based on location: no one likes to get a hint every time he or she visits your site.

The idea is to use external services for geolocation based on IP address or something similar to get a less accurate estimate of the user's location and give the user a hint only when that location is really disabled. Are there any good suggestions regarding the services that I can use for this purpose?

I know that Google has already done this: current location . It shows your current location without giving you any clues. Does anyone know how to do this?

The MaxMind database is good, but for this purpose it will require the maintenance of a huge IP database. Preferred is an API or Google service.

I am currently using the location object returned from Google Loader to estimate the location, but it is less accurate than the Google search example above.

 google.loader.ClientLocation.latitude google.loader.ClientLocation.longitude 
+6
source share
2 answers

Google current location only works because you gave Google the right to your location at a specific point in time in this browser. If you open any new browser and execute the same request, you will see that it can give a much more general location.

I am trying to find the answer to this myself, and you were on the right track with the Google downloader. The problem is that it is more or less outdated due to the reliability and accuracy of the HTML5 sentences.

I am very curious if you ever found a workaround. Some people may suggest maxmind, although I found that it was as accurate (moreso inaccurate) as google.loader.

It makes sense why the browser requests such information, I'm just surprised that there is no way to bypass / hack other than using IP addresses.

0
source

If you do not mind using a third-party API, you can use our service https://ip-api.io . It works with the client IP address and does not require any permission from the user.

Javascript example:

 $.getJSON("http://ip-api.io/json/", function(result) { console.log(result); }); 

Then you can get the location from result.latitude and result.longitude . https://ip-api.io provides much more data, such as country, city, zip code, time zone and whether this IP address is a bot, spammer or TOR node.

0
source

All Articles