2
마커 포지션을 변경할 때 마커의 주소를 알아야합니다. Google 지오 코딩 API 메소드를 synchronouslly 호출
기본적으로 내가하는 방법이 있습니다
function addNewMarker(latLng) {
geocoder.geocode({'latLng': latLng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
var address = results[0].formatted_address;
var marker = new google.maps.Marker({
position: latLng,
map: map,
draggable: true,
title: address,
});
google.maps.event.addListener(marker, 'dragend', function() {
//marker.setTitle(getGeocodeResults(marker.getPosition()));
marker.setTitle(***THIS IS NEW ADDRESS OF THIS MARKER***);
});
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
나는 새로운 방법에 지오 코딩 코드를 추출하는 경우 :
function addNewMarker(latLng){
var address = getGeocodeResults(latLng);
var marker = new google.maps.Marker({
position: latLng,
map: map,
draggable: true,
title: address,
});
google.maps.event.addListener(marker, 'dragend', function() {
marker.setTitle(getGeocodeResults(marker.getPosition()));
});
}
function getGeocodeResults(latLng){
geocoder.geocode({'latLng': latLng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
var address = results[0].formatted_address;
return address;
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
을이 호출이 비동기이기 때문에 나는 운이 없다. 움직이는 마커를 멈출 때 새로운 주소가 필요합니다. 해결 방법이 있습니까? 원래 포스터에 의해
나는 지금 그것을 얻을하지 않습니다를. 내 질문에 편집 내용을 입력해야합니까, 아니면이 대답으로 이미 편집 했습니까? 절차를 모른다. – vale4674
이 답변을 귀하의 질문에 대한 편집으로 사용하셨습니다. 그러나 대답은 대답이어야하며 질문의 일부가 아니어야합니다. 그래서 질문에서 제거하고 답변으로 여기에 넣어. – Trott
자세한 정보 :이 대답을 받아 들일 수 있습니다 (아마도 15 개의 평판 포인트를 부여하고 2 개의 평판 포인트를 부여 할 것입니다). 또는 답변을 실제로 제공하지 않은 사람에게 담당자를 제공하지 않으려는 경우 답변을 직접 게시하고 자신의 대답을 수락 할 수 있습니다. (자신의 대답을 수락하기까지 대기 시간이있을 수 있지만 자신의 대답을 수락해도 무방하며, 자신의 대답을 수락 할 때 평판 포인트를 얻지 못할 수도 있습니다.) – Trott