如果在应用启动前位置已打开,则没有问题。 如果手机的位置关闭并且我启动了应用程序,则每当我打开手机的位置(应用程序运行时)时,navigator.geolocation.getCurrentPosition都无法获取任何位置。
var app = {
onDeviceReady: function() {
this.receivedEvent('deviceready');
app.runGeolocation();
},
runGeolocation: function(){
var options = { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
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');
};
// onError Callback receives a PositionError object
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
您有什么建议吗?问候