Google地图会绘制到实际位置的路线,而不仅仅是街道地址?

时间:2018-06-25 13:59:40

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

我有一个使用ACF WordPress插件创建的Google Map。我在地图上有一些标记。我建立了一些功能,这些功能使用directionsService在地图上的不同标记之间绘制路线。我的问题是directionsRenderer在地图上放置了另一个标记,但仅在最接近已标记实际位置的街道上。我知道我可以通过使用preventMarkers关闭这个额外的标记(在屏幕快照中标记为C)。但是,我很想以某种方式实际到达原始标记。 Google Maps网站用虚线表示从道路到实际位置的位置。使用API​​可以做同样的事情吗?

这是我大部分相关的代码。

directionsDisplay.setMap(map);

directionsDisplay.setOptions({
    polylineOptions: {
        strokeColor: '#f9c606',
        strokeWeight: 4,
        clickable: false
    },
    //suppressMarkers: true,
    markerOptions: {
        marker: {
            shape: {type: 'circle', coords: [0,0,50]}
        }
    }
});


function calculateAndDisplayRoute(directionsService, directionsDisplay, start, end) {

      directionsService.route({
        origin: start,
        destination: end,
        waypoints: trailLocations,
        optimizeWaypoints: true,
        travelMode: 'DRIVING'
      }, function(response, status) {
        if (status === 'OK') {
          directionsDisplay.setDirections(response);
          var route = response.routes[0];
          var summaryPanel = document.getElementById('directions-panel');
          summaryPanel.innerHTML = '';
          // For each route, display summary information.
          for (var i = 0; i < route.legs.length; i++) {
            var routeSegment = i + 1;
            summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
                '</b><br>';
            summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
            summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
            summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
          }
        } else {
          window.alert('Directions request failed due to ' + status);
        }
      });
    }

My map.. would love to draw another line from C to the marker that is already on the map

How Google Maps handles this

0 个答案:

没有答案