geolocation without requesting permission [duplicate]
Asked Answered
A

3

7

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?

Argal answered 22/2, 2013 at 6:1 Comment(1)
You mean something like http://www.iplocation.net/. Location may be very rough, mine is 100km out for desktop and over 1,000km out for mobile. YMMV.Bleareyed
A
14

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.

Anethole answered 29/9, 2013 at 17:10 Comment(1)
You could also use: <script src="http://www.l2.io/ip.js?var=ipaddr"></script> and then the variable ipaddr will be your IPv4 address.Azote
A
1

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

Ahimsa answered 21/2, 2016 at 23:38 Comment(0)
T
0

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>
Teresetereshkova answered 6/11, 2017 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.