Geolocation without Prompt

 ̄綄美尐妖づ 提交于 2019-12-04 05:58:40

If you don't mind using 3rd party API, you can use our service https://ip-api.io . It's working with client's IP address and doesn't require any permission from user.

Javascript example:

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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!