javascript - 如何在 Google Maps directions API 中显示地点标签而不是 A 或 B?

标签 javascript google-maps google-maps-api-3 google-maps-markers

我想在 map 上显示地点名称,而不是标签 A 和 B。如何在 Google Maps Directions API 中执行此操作?例如,只需StartEndMiami PortMiami Tower

代码

    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);
        }
    });

当前 map 预览

Map Preview

最佳答案

您可以使用 suppressMarkers 属性隐藏默认标记 ABtrue

directionsDisplay = new google.maps.DirectionsRenderer({map: map, suppressMarkers: true});

然后使用 Marker 在端点制作您自己的 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/

相关文章:

javascript - 在单独的面板中创建两个网格 - Ext JS

javascript - 如何在 googlemaps url 中设置航路点

android - 在 android 中将谷歌地图缩放到以英里为单位的特定半径

javascript - Google Analytics(分析)是否与帐户中指定的域匹配或过滤流量?

Javascript:内存不足

javascript - 从 php 中按谷歌地图 api 中的城市名称自动填充州和国家/地区

php - 检查数据库中是否存在经纬度

google-maps - 切换到 maps.googleapis.com

javascript - 无法通过 AngularJS Controller 将 url 加载到 iframe

javascript - 谷歌地图api ajax视口(viewport)标记管理