我遇到了一个问题,我刚刚注意到并且从未见过我以前发布的代码。在js我打电话在Android设备上使用Chrome时出现的Modernizr错误
navigator.geolocation.getCurrentPosition()...
我也编写了回调的成功和错误部分。我遇到的问题是,在使用Chrome的Android设备上,我总是收到错误“[object PositionError]”
如果我在同一台设备上使用Firefox,那很好。我测试过的所有iOS设备也可以使用。
是否有其他人遇到这个问题,如果是的话,你找到了解决办法。
这是我的代码完全块:
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
callback(lat, lng);
}
, function (err) {
// 1 = PERMISSION_DENIED
// 2 = POSITION UNAVAILABLE
// 3 = TIMEOUT
//if (err.code == err.PERMISSION_DENIED) {
alert(err);
alert('Current location could not be obtained from the device.\r\nCheck your GPS settings.');
//}
}
, { timeout: 10000 }//10 secs.
);
} else {
alert('This device does not support GPS locations.');
}
您是在http或https页面上运行此代码吗? – Patrick
这是http不是https – JimboJones