我想在 map 上显示地点名称,而不是标签A和B。如何在Google Maps Directions API中进行操作?例如,仅将Start
和End
或Miami Port
更改为Miami Tower
。
CODE
let directionsDisplay;
let directionsService = new google.maps.DirectionsService();
let map;
directionsDisplay = new google.maps.DirectionsRenderer();
let myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
let mapArea = document.getElementById("map_canvas_track_order");
map = new google.maps.Map(mapArea, myOptions);
directionsDisplay.setMap(map);
let start = `25.757928, -80.192897`;
let end = `25.771969, -80.191235`;
let request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
CURRENT MAP PREVIEW
最佳答案
您可以使用A
属性作为B
来隐藏默认标记suppressMarkers
和true
。
directionsDisplay = new google.maps.DirectionsRenderer({map: map, suppressMarkers: true});
然后使用
Marker
在端点处创建自己的标记。var marker = new google.maps.Marker({
position: ,
label: "~what you want~",
map: map
});
关于javascript - 如何在Google Maps Directions API中显示位置标签而不是A或B?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47280913/