0
function getMyLocation() {
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(displayLocation);
}
else{
alert("Geolocation not supported");
}
}
var user_lat;
var user_long;
var d_long;
var d_lat;
function displayLocation(position) {
user_lat = position.coords.latitude;
user_long = position.coords.longitude;
alert("you are at lat: " + user_lat + " ,longitude: " + user_long);
}
function getLocationDestination() {
var e = document.getElementById("building");
var strUser = e.options[e.selectedIndex].text;
alert("you want to go to " + strUser + " and the cords are " + building_array[strUser]);
getMyLocation();
alert("heelo");
displayLocation(position);
alert("heelo");
displayLocation(position);
}
該代碼非常簡單,但是當我運行geoLocationDestination()時,我沒有從displayLocation(position)得到第二個警報,即使在運行它的while循環中也沒有發生20次。該程序在第二次打招呼後退出?有任何想法嗎?Javascript HTML5地理位置錯誤?
看起來'position'在'getLocationDestination()'中是未定義的...... – Passerby