Reputation: 15106
I know about the HTML5 way to do geolocation, but the caveat is that it has to prompt the user for permission.
navigator.geolocation.getCurrentPosition
It gets particularly annoying when I would like to do geolocation right at the home page to serve customized content based on location: no one likes to get a prompt every time he or she visits your site.
The idea is to use external services to do geolocation based on IP address or something similar to get a less accurate estimate of the user's location and give the user a prompt only when that location is really off. Are there any good suggestions as to the services I can use for that purpose?
I know Google has done this already: current location. It shows your current location without giving you any prompt. Does anyone know how to do this?
The MaxMind database is good, but that would require the maintenance of a huge IP database just for that purpose. An API or a Google service is preferred.
I currently make use of the location object returned from the 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
Upvotes: 6
Views: 9376
Reputation: 1414
Google's current location
only works because you gave Google the right to your location at some point in time on that given browser. If you were to open up any new browser and do the same query, you would see that it can only yield a much more generic location.
I've been trying to find the answer to this myself, and you were on the right track with Google's loader. The problem is that it is more or less deprecated due to the reliability and accuracy of the HTML5 offering.
I'm very curious if you ever found a workaround. Some people might suggest maxmind, though I found it to be as accurate (moreso inaccurate) as google.loader.
It makes sense why a browser would prompt for such information, I'm just surprised there isn't some kind of workaround/hack other than using IPs.
Upvotes: 0