好吧,对不起所有的日志记录我一直试图弄清楚如何返回整个对象的位置。所以我可以稍后在调用 getCurrentPosition 的函数中访问其中的项目。这是我正在尝试做的模拟。谢谢你的帮助!
function aFunctionName(){
pos = navigator.geolocation.getCurrentPosition(onGeoSuccess, geoFail);
cameraLat = pos.coords.latitude;
\\cannot read property coords
console.log(cameraLat);
cameraLong = pos.coords.longitude;
\\cannot read property coords
console.log(cameraLong);
cameraTimestamp = pos.timestamp;
console.log(cameraTimestamp)
\\Cant read property timestamp
}
function onGeoSuccess(position) {
cameraLati = position.coords.latitude;
console.log(cameraLati);
\\works fine and displays the lat
cameraLongi = position.coords.longitude;
console.log(cameraLongi);
\\works fine and displays the long
cameraTimestampi = position.timestamp;
console.log(cameraTimestampi);
\\works fine and displays the timestamp
return position;
}
function onGeofail() {
console.log("error");
}