google maps api v3 - waypoints not returned in response object -
this question exact duplicate of:
google maps route generation waypoints 1 replyi have next code, send requestobj 1 waypoint. result show me path 2 legs , 0 waypoints. want maintain waypoints. doing wrong ?
var requestobj = { origin: new google.maps.latlng(sn['lat'],sn['lng']), destination: new google.maps.latlng(en['lat'],en['lng']), travelmode: google.maps.directionstravelmode.driving, waypoints: new google.maps.latlng(45.00334,-73.00228), optimizewaypoints: true }; directionsservice.route(requestobj, function(response, status) { if (status == google.maps.directionsstatus.ok) { //process data. no way points found in : //directionsdisplay.directions.routes[0].legs[0].via_waypoints.length }});
see examples in the documentation
a waypoint consists of next fields:
location (required) specifies address of waypoint. stopover (optional) indicates whether waypoint actual stop on route (true) or instead preference route through indicated location (false). stopovers true default.
from api reference:
waypoints | array. | array of intermediate waypoints. directions calculated origin destination way of each waypoint in array. maximum allowed waypoints 8, plus origin, , destination. maps api business customers allowed 23 waypoints, plus origin, , destination. waypoints > not supported transit directions. optional.
you aren't passing in valid array of waypoints. see below:
var requestobj = { origin: new google.maps.latlng(sn['lat'],sn['lng']), destination: new google.maps.latlng(en['lat'],en['lng']), travelmode: google.maps.directionstravelmode.driving, waypoints: [{location:new google.maps.latlng(45.00334,-73.00228)}], optimizewaypoints: true }; directionsservice.route(requestobj, function(response, status) { if (status == google.maps.directionsstatus.ok) { //process data. no way points found in : //directionsdisplay.directions.routes[0].legs[0].via_waypoints.length }});
working fiddle
google-maps-api-3
No comments:
Post a Comment