Google 地图 - 路线服务 api ZERO_RESULTS

Google maps - directions service api ZERO_RESULTS

我对路线服务有疑问 API。是否有混合出行模式设置允许我为自行车绘制路线,即使该特定街道上没有自行车道或违反街道规则(甚至可能)。 我想画一条从 A 到 B 的线段,正好穿过选定的道路,而不是绕过那条路 实际上不允许朝那个方向行驶。它不必在驾驶规则方面是正确的,它必须只是在街道上画。我尝试了自行车模式而不是驾驶模式,但没有任何区别。

我希望我的 post 有意义

调用示例:

function loadRoute0() {
  var request0 = {
    origin: new google.maps.LatLng(46.56300788, 15.62779705),
    destination: new google.maps.LatLng(46.55953332, 15.62616729),
    travelMode: google.maps.TravelMode.BICYCLING
  };

  directionsService.route(request0, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var renderer = new google.maps.DirectionsRenderer({
        polylineOptions: {
          strokeColor: "#00FF00"
        },
        suppressMarkers: true,
        map: map
      });
      renderer.setDirections(result);
    }
  });
}

您可以使用 TravelMode.WALKING,它往往会给出单行道路和其他不适用于 TravelMode.DRIVING 的路线的结果。 您问题中的代码不会重现您发布的图片,而是使用 TravelMode.WALKING returns 一条路线(其中 TravelMode.BICYCLING 为发布的代码提供 ZERO_RESULTS

function loadRoute0() {
  var request0 = {
    origin: new google.maps.LatLng(46.56300788, 15.62779705),
    destination: new google.maps.LatLng(46.55953332, 15.62616729),
    travelMode: google.maps.TravelMode.WALKING
  };
  directionsService.route(request0, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var renderer = new google.maps.DirectionsRenderer({
        polylineOptions: {
          strokeColor: "#00FF00"
        },
        suppressMarkers: true,
        map: map
      });
      renderer.setDirections(result);
    } else
      console.log("status=" + status);
  });
}

代码片段:

var map;

function initialize() {
  map = new google.maps.Map(document.getElementById("map_canvas"));
  directionsService = new google.maps.DirectionsService();
  loadRoute0();

  function loadRoute0() {
    var request0 = {
      origin: new google.maps.LatLng(46.56300788, 15.62779705),
      destination: new google.maps.LatLng(46.55953332, 15.62616729),
      travelMode: google.maps.TravelMode.WALKING
    };
    var markerS = new google.maps.Marker({
      position: request0.origin,
      map: map,
      label: "S"
    });
    var markerE = new google.maps.Marker({
      position: request0.destination,
      map: map,
      label: "E"
    });
    directionsService.route(request0, function(result, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        var renderer = new google.maps.DirectionsRenderer({
          polylineOptions: {
            strokeColor: "#00FF00"
          },
          suppressMarkers: true,
          map: map
        });
        renderer.setDirections(result);
      } else
        console.log("status=" + status);
    });
  }

}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>