0
我有一個頁面在http://www.no1hastings.check.com.au/directions.html訪問者可以從任何地方獲得方向到固定點。 Google地理編碼器可以識別的目的地是街道地址(Morwong Drive 1號),但我希望它顯示Google不承認的建築物名稱(黑斯廷斯街1號)。谷歌地圖方向目的地別名
是否有辦法將街道地址設置爲目的地,但在顯示結果時將其別名替換爲建築物名稱?
我有一個頁面在http://www.no1hastings.check.com.au/directions.html訪問者可以從任何地方獲得方向到固定點。 Google地理編碼器可以識別的目的地是街道地址(Morwong Drive 1號),但我希望它顯示Google不承認的建築物名稱(黑斯廷斯街1號)。谷歌地圖方向目的地別名
是否有辦法將街道地址設置爲目的地,但在顯示結果時將其別名替換爲建築物名稱?
一種選擇是將其發送到的DirectionsRenderer之前修改在響應中的字符串:
function calcRoute() {
var request = {
origin: 'Brisbane QLD Australia Australia',
// origin: 'Brisbane Qld, Australia',
destination: '1 Morwong Drive, Noosa Heads Qld, Australia',
// waypoints:[{location: 'Bourke, NSW'}, {location: 'Broken Hill, NSW'}],
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var route = response.routes[0];
var lastleg = route.legs[route.legs.length-1];
response.routes[0].legs[route.legs.length-1].end_address = 'No. 1 in Hastings Street';
directionsDisplay.setDirections(response);
} else alert("Directions request failed: "+status);
});
}
來處理情況,方向是由的DirectionsRenderer(即用於拖動原點)改變的情況下,你可以做這樣的事情(其中changeEnd是一個全球性的,並設置爲false),請注意,它會有不希望的結果,如果用戶拖動目標(可能要防止:Google maps api v3 Two markers one fixed one dragged):
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.directions);
if (!changeEnd) {
var response = directionsDisplay.getDirections();
var route = response.routes[0];
var lastleg = route.legs[route.legs.length-1];
response.routes[0].legs[route.legs.length-1].end_address = 'No. 1 in Hastings Street';
changeEnd = true;
directionsDisplay.setDirections(response);
} else changeEnd = false;
});
完美的作品如果從中選擇一個起點下拉列表。如果有人將A標記拖到不同的地方,它會顯示街道地址,而不是「否」。 1在黑斯廷斯街'。 –
您是否嘗試添加代碼來處理這種情況?關閉可拖動的方向可能會更好。 – geocodezip
或類似的[這,只允許一個可拖動的標記](http://stackoverflow.com/questions/16966766/google-maps-api-v3-two-markers-one-fixed-one-dragged/16972214#16972214 ) – geocodezip