gpt4 book ai didi

Iphone HTML5 Geolocation 总是返回错误

转载 作者:太空狗 更新时间:2023-10-29 14:43:27 24 4
gpt4 key购买 nike

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

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

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

有办法做到这一点吗?

最佳答案

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

}

关于Iphone HTML5 Geolocation 总是返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6271191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com