我遇到了一个我刚才注意到并且从未见过我之前发布的代码的问题。在js我打电话
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.');
}