Iphone HTML5 地理定位总是返回错误
我尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保设备上的定位服务已针对 Safari 开启。转到“设置”>隐私>定位服务> Safari 并确保其设置为
ON
。然后尝试这段代码:
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:
我使用了appMobi的js,如果我在iPhone上的Safari中重新加载一个网站,它工作得很好。但是,主屏幕加书签的应用程序并没有这样做(即使我在网络应用程序上为新版本添加了书签)。
新的 js 可以正常加载到添加书签的应用程序中(每次更新代码时,我都会添加一条带有新提示的弹出消息,只是为了确保 Web 应用程序正在加载新的 js),如果我想要,iPhone 会提示我允许网站检查,但当我说“是”时什么也没有发生。而在 Safari 中,它显示纬度/经度。
有人遇到过类似的问题吗?
更新:它可以工作,但仅在第一次加载页面时 - 第二次加载页面时,它显示“开始”,但不会显示纬度/经度...
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...