首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >谷歌地图-导航服务api ZERO_RESULTS

谷歌地图-导航服务api ZERO_RESULTS
EN

Stack Overflow用户
提问于 2018-06-10 02:29:50
回答 1查看 1.5K关注 0票数 1

我有一个关于方向服务API的问题。有没有一种混合出行模式设置,可以让我为一辆自行车画一条路线,即使那条特定的街道上没有自行车道,或者这违反了街道规则(这是否可能)。我想画一条从A到B的线段,准确地穿过选定的道路,如果那条道路实际上不允许在那个方向上行驶,就不能绕着它走。它不一定要在驾驶规则方面是正确的,它必须只是画在街道上。我尝试了自行车模式,而不是驾驶模式,但没有任何区别。

我希望我的帖子有任何意义

调用示例:

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-10 03:40:45

你可以使用TravelMode.WALKING,它倾向于给出对TravelMode.DRIVING不起作用的单向道路和其他路线的结果。问题中的代码不会复制您发布的图片,但使用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);
  });
}

代码片段:

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>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50777351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档