How do I display place labels instead of A or B in Google Maps directions API?

Viewed 1670

I want to display names of the places on the map instead of labels A and B. How do I do it in Google Maps Directions API? For example, just Start and End or Miami Port to 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

Map Preview

1 Answers

You can hide default Marker A and B using suppressMarkers property as true.

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

And then Make your own Marker at the end points using Marker.

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