Iphone HTML5 Geolocation always return a error

17,031

Make sure that your Location Services on the device are on for Safari. Go to Settings > Privacy > Location Services > Safari and make sure it is set to ON.

Then try this code:

function doGPS()
{
    try{
        //position request
        navigator.geolocation.getCurrentPosition( function (position) { 
        alert(position.coords.latitude);
        alert(position.coords.longitude);
        });
    }
    catch(evt)
    {
        alert(evt.message);
    }

}
Share:
17,031
Garou
Author by

Garou

Updated on June 15, 2022

Comments

  • Garou
    Garou almost 2 years

    I trying to use html5 geolocation on Iphone, but it always returns a error.

    var win = function(position) { alert('Everything is fine! ' + position) };
    var fail = function(e) { alert('Can\'t retrieve position.\nError: ' + e) };
    navigator.geolocation.getCurrentPosition(win, fail);

    I testing on IOS Simulator and my device, but doesnt work. On Safari i just can get my position using a wireless internet connection (??).

    There's a way to make this work?

  • zzz
    zzz about 12 years
    Turning on location services worked for me. I tried testing it at: html5demos.com/geo Question: is location services for safari turned on or off by default?