Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geolocation without requesting permission [duplicate]

Ive noticed that modern html5 based geolocation always asks the user "do you want to share your location with this website?". Which is fine, but I know there are other routes of trying to determine a ballpark geolocation without having to request this permission. If I recall, these services uses ip databases to try to track geolocaiton info and provide it to a web app.

So, in my website I would like to get a "best guess" at the user's zip code, without the geolocation permission being requested. What's the simplest and/or best method of doing this?

like image 306
Brady Moritz Avatar asked Feb 22 '13 06:02

Brady Moritz


People also ask

How do you get geolocation without permission?

// You can go for an external service like // https://www.geolocation-db.com // They provide a geolocation service based on IP addresses // where you don't need user permission.

How to use permission API?

Concepts and usage Once you have this object you can then perform permission-related tasks, for example querying a permission using the Permissions. query() method to return a promise that resolves with the PermissionStatus for a specific API. Not all APIs' permission statuses can be queried using the Permissions API.


2 Answers

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.

like image 104
Ben Dowling Avatar answered Sep 18 '22 14:09

Ben Dowling


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

like image 31
Philip Avatar answered Sep 16 '22 14:09

Philip