Google map api Error: error in <waypoints> properties:

I am trying to set some waypoints on google maps api but get the following error. I know that this has something to do with setting the object, but I cannot figure out how to do it right. I also cannot find exact articles on it.

Error: Error in property <waypoints>: (Invalid value: Ballybricken, Waterford, Ireland,The Glen, Waterford (Error in element at position 0: (Unknown property <0>))) 

My code

 var waypts = ["Ballybricken, Waterford, Ireland", "The Glen, Waterford"]; drawPolyline('Waterford Regional Hospital', 'Hillview, Waterford, Ireland', waypts); function drawPolyline(source,destination,waypoints){ // show route between the points directionsService = new google.maps.DirectionsService(); directionsDisplay = new google.maps.DirectionsRenderer( { suppressMarkers: true, suppressInfoWindows: true, polylineOptions: { strokeColor: '#000000', strokeOpacity: 0.5 } }); directionsDisplay.setMap(map); var request = { origin:source, destination:destination, waypoints:waypoints, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } 
+4
source share
1 answer

The waypoint is not an address or latLng, it is an object that consists of a (mandatory) location -member and a (optional) stopover -member, so your array should look like this:

 var waypts = [{location:"Ballybricken"}, {location:"Waterford"}, {location:"Ireland"}, {location:"The Glen"}, {location:"Waterford"}]; 
+5
source

All Articles