1
我試圖從navigator.geolocation.getCurrentPosition
函數返回位置值。來自Cordova的getCurrentPosition的返回值
在this科爾多瓦文檔navigator.geolocation.getCurrentPosition
使用onSuccess
和onError
函數來得到這個職位,但我需要的是這樣的:
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');
}
而我想要的是:
var p = navigator.geolocation.getCurrentPosition(onSuccess, onError);
我應該如何恢復從navigator.geolocation.getCurrentPosition
到p的值?