当调用 navigator.geolocation.getcurrentPosition
时,我该如何传递一个或多个参数给成功回调函数?
我怎样才能把 foundLoc
中的 deviceready
参数传递给 getGeoLoc
方法?
var app = {
onDeviceReady: function () {
alert = window.alert || navigator.notification.alert;
app.getGeoLoc('deviceready');
},
getGeoLoc: function (id) {
navigator.geolocation.getCurrentPosition(this.foundLoc, this.noLoc, { timeout: 3 });
},
foundLoc: function (position) {
var parentElement = document.getElementById('deviceready');
var lat = parentElement.querySelector('#lat');
var long = parentElement.querySelector('#long');
lat.innerHTML = position.coords.latitude;
long.innerHTML = position.coords.longitude;
},
noLoc: function () {
alert('device has no GPS or access is denied.');
}
};