Reputation: 177
my previous question: https://stackoverflow.com/questions/29581698/getcurrentposition-fails-behind-vpn got closed for being "unclear". the instructions indicated I should reword the question but having done so, the question remained closed. I'm thus opening a new issue with the re-worded question.
I use AirVpn.org and have noticed that whilst active, geolocation fails: if I turn off the VPN client, the code below displays 'works', turn it on, I get 'The current position could not be determined'.
if (!navigator.geolocation) {
alert('No navigator');
} else navigator.geolocation.getCurrentPosition(
function() { alert('works'); },
function(e) { alert(e.message); }, {
timeout: 30000,
enableHighAccuracy: true,
maximumAge: 75000
});
what I'm asking is, what is the reason for which a request for current position from the geo-locator would fail when connected to the Internet through a VPN but not otherwise? specifically, I'm interested to know what the mechanism that the navigator.geolocation
software uses for determining position and why that mechanism might not work under VPN conditions
Upvotes: 3
Views: 1638
Reputation: 2994
There are multiple ways how browsers determine your position. If you don't have position sensors like GPS on your device, several fallbacks exist. Among them chiefly geolocation by nearby WiFi hotspots and, if that fails, IP-based location. Both of these require an active internet connection, as they send the WiFi identifiers and/or IP to the server and it resolves them to probable location. As far as I know, they also require working TLS (port 443), so if your VPN is stripping HTTPS, you might not be able to get your location, as you cannot get the response to your query about "where am I based on what WiFi's I can receive".
More probable however is the fact that among other things, VPN masks your IP address. So if your "working" geolocation is based only on the IP address, it will fail when on VPN. You can tell your location was IP-based by its very low accuracy, usually in tens of kilometers, while WiFi location is usually in tens or hundreds of meters. These geolocation services get pretty smart, so they may have VPN addresses "blacklisted" and resolve their IPs to "unknown".
Another possibility that occurs to me may be the mismatch between your IP and WiFi location, resulting in ambiguous state which again resolves to "unknown".
My money would be on the fact that you're on IP-only location and the geolocation service cannot or doesn't want to resolve your "masked" address.
Upvotes: 4