Hi there. I am trying to create a function that calculates the duration of
the changed route. I am relatively new to google maps API and I am sure I am
making a simple mistake or may be going about it all wrong.
The function is called by
<code>
google.maps.event.addListener(directionsDisplay,
'directions_changed', function() {
recalcRoute(directionsDisplay.directions);
});
</code>
<code>
function recalcRoute(result) {
var waypts_start=[];
var waypts_end=[];
var total = 0;
var ttime = 0;
var end_point;
var start_point;
var myRouteSteps;
var myroute = result.routes[0];
for (i = 0; i < myroute.legs.length; i++) {
total += myroute.legs[i].distance.value;
myRouteSteps = result.routes[0].legs[i];
for (var j = 0; j < myRouteSteps.steps.length; j++) {
start_point=myRouteSteps.steps[j].start_point;
start_point =String(start_point);
start_point=start_point.replace('(', '');
start_point=start_point.replace(')', '');
temp = start_point.split(',');
var start_lat =parseFloat(temp[0]);
var start_long =parseFloat(temp[1]);
start_point = new google.maps.LatLng(start_lat,start_long);
end_point=myRouteSteps.steps[j].end_point;
end_point =String(end_point);
end_point=end_point.replace('(', '');
end_point=end_point.replace(')', '');
temp = end_point.split(',');
var end_lat =parseFloat(temp[0]);
var end_long =parseFloat(temp[1]);
end_point = new google.maps.LatLng(end_lat,end_long);
waypts_start.push(start_point);
waypts_end.push(end_point);
}
}
service.getDistanceMatrix(
{
origins: [waypts_start],
destinations: [waypts_end],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
}, callback);
}
</code>
The script does not get to the callback and I receive this error
Error in property <origins>: (Invalid value at position 0:
(-28.85575000000001, 153.04764999999998),(-28.85749,
153.05716000000007),(-28.85474, 153.06182),(-28.83969,
153.07271000000003),(-28.78573, 153.12441),(-28.79623,
153.19927000000007),(-28.77588, 153.18682))
Could anyone give me some tips
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-maps-js-api-v3/-/S5DTDvHKGH4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.