Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone HTML5 Geolocation always return a error

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?

like image 916
Garou Avatar asked Jun 07 '11 20:06

Garou


1 Answers

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);
    }

}
like image 98
profMobi Avatar answered Sep 23 '22 07:09

profMobi