Google Maps API - 我只需要一个航点

时间:2014-01-21 22:06:41

标签: javascript google-maps-api-3

我从一个文本框中得到了只有一个WAYPOINT的值,我尝试通过这个航路点从头到尾绘制一条路线,但它不起作用。

function calcRoute() {
    var start = document.getElementById('start').value;
    var end = document.getElementById('end').value;
    var waypts = document.getElementById('way').value;

    var request = {
        origin: start,
        destination: end,
        waypoints: waypts
    };

1 个答案:

答案 0 :(得分:1)

请阅读documentation on waypoints

waypts需要是DirectionsWaypoint objects

的数组
function calcRoute() {
  var start = document.getElementById('start').value;
  var end = document.getElementById('end').value;
  var waypts = document.getElementById('way').value;

  var request = {
    origin: start,
    destination: end,
    waypoints: [{location:waypts, stopover: true}]
  };

example with single waypoint