Google Maps-绘制没有标记的路线

Dor*_*oro 0 javascript google-maps

我正在使用Google Maps API绘制两点路线,但此图给我带来了一些不便。当我绘制路线时,Google会在地图上向我显示两个点,即A和B,即起点和终点。

问题是我无法将其取出。我只需要显示没有此标记的路线。

有人知道如何仅显示路线吗?

该代码基于开发人员指南https://plnkr.co/edit/UWfKc7XGHtdbeRZkUS8X?p=preview中的示例

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
        <title>Directions service (complex)</title>
        <style>
            /* Always set the map height explicitly to define the size of the div
             * element that contains the map. */
            #map {
                height: 100%;
            }
            /* Optional: Makes the sample page fill the window. */
            html, body {
                height: 100%;
                margin: 0;
                padding: 0;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>
        <script>
            var startLatLng;
            var endLatLng;
            var startAddr = 'Grand Central Station';
            var endAddr = 'City Hall';

            function initMap() {
                // Create a map and center it on Manhattan.
                var map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 13,
                    center: {lat: 40.771, lng: -73.974}
                });

                var directionsService = new google.maps.DirectionsService;
                var directionsDisplay = new google.maps.DirectionsRenderer({map: map});
                calculateAndDisplayRoute(directionsDisplay, directionsService);
            }

            function calculateAndDisplayRoute(directionsDisplay, directionsService) {
                // Retrieve the start and end locations and create a DirectionsRequest using DRIVING directions.
                directionsService.route({
                    origin: startAddr,
                    destination: endAddr,
                    travelMode: 'DRIVING'
                }, function(response, status) {
                    // Route the directions and pass the response to a function to create markers for each step.
                    if (status === 'OK') {
                        directionsDisplay.setDirections(response);
                        console.log(response);
                    } else {
                        console.log('Directions request failed due to ' + status);
                    }
                });
            }
        </script>
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCgkOZvjHinGyRsQT7WO1R7KGmtxJJfDPE&callback=initMap">
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Dor*_*oro 5

我找到了解决方案:

directionsDisplay.setOptions({suppressMarkers: true});
Run Code Online (Sandbox Code Playgroud)