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 (위치)에서 두 번째 경고를받지 못합니다. while 루프에서는 20 번 실행하지 않습니다. 두 번째 안녕하세요 후 프로그램이 종료됩니까? 어떤 아이디어? 당신이 별도로 위치 매개 변수를 전달이 getMyLocation에서 기능하지 호출 할 필요가 있기 때문에 내가 당신의 코드를 실행하면자바 스크립트 HTML5 Geolocation 버그?
getLocationDestination()에서'position'이 정의되지 않은 것 같습니다 ... ... – Passerby