0
即时创建一个路线淋浴与地理编码和反向地理编码。 工作得很好,但是当我想拖动标记时,我想用更新的地址更新正确的输入。问题在于我无法摆脱起点和终点。使用下面的代码,如果我只有1点它正确地更新开始地址,但添加另一个点后,他们都开始更新相同的输入。 (不知道我是否有一个好主意来区分他们的属性 - 我将这些点添加到数组,并根据它的长度,它应该添加属性目的地'开始'或'停止'。好像添加第二个标记后更新前一个目标值)。区分标记地图api v3
function placeMarker(location) {
if(list.length < 2) {
marker = new google.maps.Marker({
position: location,
map: map,
draggable:true,
animation: google.maps.Animation.DROP,
destination: 'start'
});
map.setCenter(location);
list.push(marker);
if (list.length == 2) {
list[1].destination = 'stop';
};
geocoder.geocode({'latLng': location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
if(list.length == 1) {
$('#start').val(results[0].formatted_address);
} else {
$('#end').val(results[0].formatted_address);
}
}
}
});
}
if (list.length == 2) {
drawRoute(list[0].getPosition(), list[1].getPosition());
};
google.maps.event.addListener(marker, 'drag', function(event) {
console.log(marker.destination);
geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (marker.destination == 'start') {
$("#start").val(results[0].formatted_address);
} else {
$("#end").val(results[0].formatted_address);
}
}
});
});
};
谢谢你的帮助!