首页 文章

Iphone HTML5 Geolocation始终返回错误

提问于
浏览
6

我试图在Iphone上使用html5地理位置,但它总是返回错误 .

var win = function(position){alert('Everything is fine!'position)}; var fail = function(e){alert('无法检索位置 . \ n错误:'e)}; navigator.geolocation.getCurrentPosition(win,fail);

我在IOS模拟器和我的设备上测试,但不起作用 . 在Safari上,我可以使用无线互联网连接获取我的位置(??) .

There's a way to make this work?

2 回答

  • 16

    确保设备上的位置服务已启用Safari . 转到设置>隐私>位置服务> Safari,并确保将其设置为 ON .

    然后试试这段代码:

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

    我已经使用了appMobi的js,如果我在iPhone上重新加载Safari中的网站,它可以正常工作 . 但是,主屏幕书签应用程序没有这样做(即使我在Web应用程序上为新版本添加书签) .

    新js正在加载到书签应用程序中(我每次更新代码时都添加了一个带有新提示的弹出消息,只是为了确保Web应用程序正在加载新的js),如果我想要iPhone,我会提示我允许网站检查,但当我说是的时候没有任何反应 . 而在Safari中,它显示纬度/经度 .

    有人有类似的问题吗?

    更新:它工作,但只有你第一次加载页面 - 第二次通过,它显示'开始',但不会显示纬度/经度...

    if (navigator.geolocation) {
      alert('Geolocation is supported!');
    }
    else {
      alert('Geolocation is not supported for this Browser/OS version yet.');
    }
    
    try{
        //position request
       alert('start');
        navigator.geolocation.getCurrentPosition( function (position) { 
        alert(position.coords.latitude);
        alert(position.coords.longitude);
        });
    }
    catch(evt)
    {
        alert('fail'+evt.message);
    }
    

相关问题