Reputation: 264
I have this basic function for indentify the position of the user:
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showmyPosition, errorCallback);
}
else
{
alert("Geolocation is not supported by this browser.");
}
}
function showmyPosition(position)
{
document.location.href="/search?lat="+ position.coords.latitude +"&lng="+ position.coords.longitude +"";
}
function errorCallback(error) {
if (error.code === 1) {
alert("User denied geolocation");
}
}
Works fine on Firefox, Chrome and Explorer but doesn't work on Safary (neither on iPhone). Why?
Upvotes: 1
Views: 308
Reputation: 1899
In case geolocation is turned off in configuration, it won't work. In addition it requires a secure (HTTPS) protocol. You could also have a look at JS-lib: https://code.google.com/archive/p/geo-location-javascript/
Upvotes: 1