简体   繁体   English

Google Maps-路线服务API ZERO_RESULTS

[英]Google maps - directions service api ZERO_RESULTS

I have a question regarding directions service API. 我对路线服务API有疑问。 Is there a hybrid travel mode setting which would allow me to draw a route for a bike, even if there isn't a bike track on that particular street or it's against street rules (is it even possible). 是否有混合旅行模式设置,即使在该特定街道上没有自行车道或违反街道规定(甚至可能),我也可以为它绘制自行车路线。 I would like to draw a segment which will go from A to B exactly through selected road, and not around if that road doesn't actually allow driving in that direction. 我想画一条线段,它将从A到B完全通过选定的道路,如果该道路实际上不允许沿该方向行驶,则不围绕该路段。 It doesn't have to be correct in regard to driving rules, it must be just drawn over the street. 就驾驶规则而言,它不一定是正确的,而必须在街道上绘制。 I tried bicycle mode instead of driving mode, but there isn't any difference. 我尝试了自行车模式而不是驾驶模式,但是没有任何区别。

I hope my post makes any sense 希望我的帖子有意义

蓝色是Google制作的路线,我需要黄色的路线

Example of call: 通话示例:

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);
    }
  });
}

You could use TravelMode.WALKING , that tends to give results for one way roads and other routes that won't work for TravelMode.DRIVING . 您可以使用TravelMode.WALKING ,它倾向于给出不适用于TravelMode.DRIVING单向道路和其他路线的结果。 The code in your question doesn't reproduce the picture you posted, but using TravelMode.WALKING returns a route (where TravelMode.BICYCLING gives ZERO_RESULTS for the posted code) 您问题中的代码不会复制您发布的图片,而是使用TravelMode.WALKING返回一条路线(其中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);
  });
}

生成的地图的屏幕截图

生成的地图的屏幕截图

code snippet: 代码段:

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM