我遇到了一個問題,我剛剛注意到並且從未見過我以前發佈的代碼。在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