user2472368
user2472368

Reputation: 199

Google Maps API - I need only one waypoint

I get the value of ONLY ONE WAYPOINT from a text box and I try to draw a route from start to end through this waypoint but it doesn't work.

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

Upvotes: 0

Views: 259

Answers (1)

geocodezip
geocodezip

Reputation: 161404

Please read the documentation on waypoints

waypts needs to be an array of 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

Upvotes: 1

Related Questions