Iphone HTML5 地理定位总是返回错误

发布于 2024-11-14 01:16:05 字数 367 浏览 4 评论 0原文

我尝试在 iPhone 上使用 html5 地理定位,但它总是返回错误。

var win = function(position) {alert('一切都很好!' +position) };
varfail = function(e) {alert('无法检索位置。\n错误: ' + e) };
navigator.geolocation.getCurrentPosition(胜利,失败);

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

有办法做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天暗了我发光 2024-11-21 01:16:06

确保设备上的定位服务已针对 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);
    }

}

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

}
榆西 2024-11-21 01:16:06

我使用了appMobi的js,如果我在iPhone上的Safari中重新加载一个网站,它工作得很好。但是,主屏幕加书签的应用程序并没有这样做(即使我在网络应用程序上为新版本添加了书签)。

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

I've used appMobi's js, and it works fine if I reload a site in Safari on the iPhone. However, home screen bookmarked apps aren't doing it (even if I bookmark a new version on the web app).

The new js is loading into the bookmarked app fine (I added a pop up message with a new prompt each time I updated the code, just to make sure the web app is loading the new js), and the iPhone promtps me if I want to allow the site to check, but nothing happens when I say yes. Whereas in Safari, it displays the lat/long.

Anyone had a similar problem?

UPDATE: it works, but only the first time you load a page - the second time through, it displays 'start', but won't display the lat/long...

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文