在路线中使用航点 - 路线服务Google地图 [英] Using Waypoints in Routes - Directions Service Google Maps

查看:95
本文介绍了在路线中使用航点 - 路线服务Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将路点添加到我的谷歌地图 - 功能calcRoute不起作用。
如何正确设置航点?



谢谢。

 <脚本> 
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

函数initialize(){
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033,-87.6500523);
变种的MapOptions = {
变焦:55,
的mapTypeId:google.maps.MapTypeId.ROADMAP,
中心:CHICAGO
}
地图=新的谷歌.maps.Map(document.getElementById('map_canvas'),mapOptions);
directionsDisplay.setMap(map);
}

函数calcRoute(){

var start =Berlin;
var end =巴黎;
var waypts = [Frankfurt];

变种请求= {
起源:启动,
目的地:端,
航点:waypts,
optimizeWaypoints:真,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(请求,功能(响应,状态){
如果(状态== google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(响应);
}
});
}
< / script>

https://developers.google.com/maps/documentation/javascript/directions?hl=pl#Waypoints

解决方案

阅读您引用的文档,字符串Frankfurt不是有效的航点

位置为Frankfurt的单个航点看起来像这:

  [{location:Frankfurt,stopover:false}] 

设置适当的中途停留时间。


If I add waypoints to my google map - function calcRoute not working. How to set waypoints correctly?

Thanks.

<script>
      var directionDisplay;
      var directionsService = new google.maps.DirectionsService();
      var map;

      function initialize() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var chicago = new google.maps.LatLng(41.850033, -87.6500523);
        var mapOptions = {
          zoom:55,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          center: chicago
        }
        map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
        directionsDisplay.setMap(map);
      }

      function calcRoute() {

        var start = "Berlin";
        var end = "Paris";
        var waypts = ["Frankfurt"];

    var request = {
            origin:start,
            destination:end,
            waypoints:waypts,
            optimizeWaypoints: true,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
          }
        });
      }
    </script>

https://developers.google.com/maps/documentation/javascript/directions?hl=pl#Waypoints

解决方案

Reading the documentation that you reference, the string "Frankfurt" is not a valid waypoint.

A single waypoint with the location "Frankfurt" would look like this:

[{ location: "Frankfurt", stopover: false}]

with the value of stopover set appropriately.

这篇关于在路线中使用航点 - 路线服务Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆