1
私はGoogle Maps API v3を使用しています。マーカードラッグ終了機能に基づいてレンダリングされた指示を実装しました。しかし、マーカーを再びドラッグすると、元の方向のセットは削除されません。Googleマップマーカードラッグ終了方向 - 以前のルートをクリアする
マップは、ジオコーディング要求とソースのオートコンプリートテキストボックスに基づいて生成され、宛先は静的です。これはすべて正常に動作します。私はAPIのドキュメントを読んで、それは.setMap(null);私は地図を再生成していないので、私はこれが正しいと信じています。方向のレンダリングのコードは次のとおりです:
google.maps.event.addListener(markersrc, 'dragend', function() {
geocoder.geocode({ 'latLng': markersrc.getPosition() }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var request = {
origin: markersrc.getPosition(),
destination: markerdst.getPosition(),
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
directionsDisplay.suppressMarkers = true;
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("directions_panel"));
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
});
});
どのように私は元の方向をクリアすることができますか考えている?
ありがとうございました。それを修正する正しい方法でした! –