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() 时,即使在运行 20 次的 while 循环中,我也没有从 displayLocation(position) 收到第二个警报。程序在第二个 hello 后退出?有任何想法吗?