【问题标题】:How do I display place labels instead of A or B in Google Maps directions API?如何在 Google Maps Directions API 中显示地点标签而不是 A 或 B?
【发布时间】:2017-11-14 08:28:03
【问题描述】:

我想在地图上显示地点的名称,而不是标签 A 和 B。如何在 Google Maps Directions API 中执行此操作?例如,只需 StartEndMiami PortMiami 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

【问题讨论】:

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


    【解决方案1】:

    您可以使用suppressMarkers 属性作为true 隐藏默认标记AB

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

    然后使用Marker 在端点制作自己的标记。

    var marker = new google.maps.Marker({
                    position: ,
                    label: "~what you want~",
                    map: map
                });
    

    【讨论】:

    猜你喜欢
    • 2016-10-14
    • 2023-04-02
    • 2016-10-22
    • 1970-01-01
    • 2023-02-12
    • 2020-09-20
    • 1970-01-01
    • 2011-05-24
    • 2015-07-24
    相关资源
    最近更新 更多