Basj
Basj

Reputation: 46401

Get geolocation if and only if it is possible silently (without user approval popup)

It's well known how to get geolocation, after user approval:

enter image description here

On my computer, with Firefox, the approval popup is displayed. But if I remember well, on some devices (iPad? phone?), geolocation is sometimes approved by default (is it correct?).

Is it possible to get geolocation if and only if it is possible silently (without user approval popup)? i.e. a popup will never appear, i.e. :

either it's possible to get geolocation without popup, then get it (phone, iPad), or it's not possible, then don't ask approval, don't get browser geolocation (then maybe I'll use IP-geolocation).

Upvotes: 2

Views: 465

Answers (1)

steveshapiro8855
steveshapiro8855

Reputation: 31

Looks like you are requesting location data from the browser, which might be more accurate but requires approval.

If you can just get the IP of the visitor, with whatever backend language you are using on your server, you can get the location data from an IP location service like https://getipdata.com.

Whilst they're not accurate to street level, you can get a good idea about the city/state/country the user is in. That is of course, if they're not using a proxy or VPN.

Example: https://getipdata.com/8.8.8.8

Upvotes: 1

Related Questions