geolocation without requesting permission

南楼画角 提交于 2019-11-30 20:47:56

IP geolocation is less accurate, but you don't need user permission for it. The http://ipinfo.io API (which is my service) makes it extremely simple. Here's a jQuery example:

$.get("http://ipinfo.io", function(response) {
    console.log(response.city, response.region, response.country);
}, "jsonp");

More details are available here.

Philip

Use a IP location script on the back-end using the _SERVER variables. This is the only way without permission, but with huge disadvantages: 1) It is not accurate at all 2) The IP address can be altered by the user if they're using a proxy

But still, it's the only way if you don't want to ask permission.

Or you could just ask the user for their zip code, since they want to use you site, they might as well :)

Also, have a look at this post: Geolocation without Prompt

With the https://ipdata.co API

$.get("https://api.ipdata.co", function (response) {
    $("#response").html(JSON.stringify(response, null, 4));
}, "jsonp");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="response"></pre>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!