2017-02-09 2 views
-1

Я рисую маршрут для двух точек с помощью API Карт Google, но у меня есть некоторые неудобства из этого чертежа. Когда я рисую маршрут, Google показывает мне на карте две точки: A и B, точку начала и пункта назначения.Карты Google - рисование маршрута без маркеров

Проблема в том, что я не могу ее вынуть. Мне нужно показать только маршрут без этих маркеров.

Кто-нибудь знает, как показать только маршрут?

код основан на примере из разработчиков руководства 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> 
+0

Я довольно уверен, что вы можете предоставить варианты при инициализации карты, чтобы скрыть маркеры. В противном случае посмотрите здесь: https://developers.google.com/maps/documentation/javascript/examples/marker-remove?hl=de – p0rter

+0

Я знаю, как скрыть/удалить некоторые маркеры, но проблема в том, что я не знаю, где я нахожу эти два маркера ... – Doro

ответ

0

Я нашел решение:

directionsDisplay.setOptions({suppressMarkers: true}); 
Смежные вопросы