谷歌地图航点不起作用

Google Maps waypoints not working

本文关键字:不起作用 谷歌地图      更新时间:2023-09-26

所以,我不知道这段代码有什么问题,需要帮助。

我希望用户输入起点、航点和结束地址。

var start = document.getElementById('start').value;
var way = document.getElementById('way').value;
var end = document.getElementById('end').value;

var request = 
     {
       origin: start,
       destination: end,
       waypoints: way,
       travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
......

......

 <strong>Start:</strong>
  <input id="start" type="text" ></input>
  <strong>Waypoint:</strong>
  <input id="way" type="text" ></input>
  <strong>End:</strong>
  <input id="end" type="text" ></input>

似乎不明白我哪里弄错了,提前感谢您的解释。

Waypoints是DirectionsWaypoint对象的数组。 这些对象包含 LatLng 对象或地址字符串以及布尔中途停留属性。

试试这个:

var waypoints = [];
waypoints.push({
     location:document.getElementById('way').value,
     stopover:true // true by default. Technically this property is optional.
});

这是一个使用航点的谷歌示例应用程序。

>根据文档waypoints应该是一个数组

如果您只有一个,请使用

waypoints: [way],

传递单个元素的数组。