我使用了文档中的示例。我用我的坐标得到警报,但如果我阻止GPS或关闭它,没有任何反应。如果我更换 navigator.geolocation.getCurrentPosition(onSuccess,onError); 同 navigator.geolocation.getCurrentPosition(onerror的); 显示警报。
有人有想法吗?
这是代码,从文档
中可以看出navigator.geolocation.getCurrentPosition(onSuccess, onError);
//AKTUELLE POSITION ERMITTELN
var onSuccess = function(position)
{
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
}
//Error Callback für eigene Position
function onError(error)
{
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
答案 0 :(得分:0)
试试这个:
navigator.geolocation.getCurrentPosition(onSuccess, onError);
//AKTUELLE POSITION ERMITTELN
function onSuccess(success)
{
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
}
//Error Callback für eigene Position
function onError(error)
{
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}