Using the Directions API (Google), is it possible to get the mileage between each waypoint?
We're doing something more or less like this, but finding it hard to get the mileage between stop A and B and another set of mileage between B and C.
var
its: TTMSFNCDirectionsItems;
it: TTMSFNCDirectionsItem;
I: Integer;
I2 : Integer;
DirectionsHTML : String;
DistanceHTML : String;
EstimatedTimeToArrival : Double;
TotalDistance : Double;
begin
TMSFNCGoogleMaps1.BeginUpdate;
TMSFNCGoogleMaps1.CloseAllPopups;
TMSFNCGoogleMaps1.ClearPolylines;
TotalDistance := 0;
its := ARequest.Items;
for I := 0 to its.Count - 1 do
begin
it := its[I];
if it.Coordinates.Count > 0 then
TMSFNCGoogleMaps1.AddPolyline(it.Coordinates.ToArray).StrokeColor := gcRed;
DirectionsHTML := DirectionsHTML + '<table border=1 frame=void rules=rows>';
DirectionsHTML := DirectionsHTML + '<tr><td width="500px"><b>Directions</b></td><td align="right"><b>Miles</b></td></tr>';
for I2 := 0 to IT.Steps.Count - 1 do
begin
TotalDistance := TotalDistance + IT.Steps[I2].Distance;
DirectionsHTML := DirectionsHTML + '<tr>';
DirectionsHTML := DirectionsHTML + '<td width="500px">' + IT.Steps[I2].Instructions + '</td>';
DirectionsHTML := DirectionsHTML + '<td align="right">' + FormatFloat('0.00', Ceil(IT.Steps[I2].Distance / 1000) * 0.62137) + '</td>';
DirectionsHTML := DirectionsHTML + '</tr>';
end;
DirectionsHTML := DirectionsHTML + '</table>';
end;
{Calc EstimatedTimeToArrival}
try
{Meters to Miles Calc divided by AverageMPH}
EstimatedTimeToArrival := (TotalDistance * 0.00062137) / 60;
EstimatedTimeToArrival := StrToFloat(FormatFloat('0.00', EstimatedTimeToArrival));
except
EstimatedTimeToArrival := 0;
end;
DistanceHTML := '<b>TOTAL Distance: ' + FormatFloat('0.00', (TotalDistance * 0.00062137)) + ' miles. <br>' +
'Going 60 miles per hour, full route will take ' + EstimatedTimeToArrival.ToString + ' hours</b><br><br>';
TMSFNCGoogleMaps1.EndUpdate;
DisplayDirections(DistanceHTML + DirectionsHTML);
Do we need to run Directions ourselves for each segment, or is it possible to extract from a single Directions Request?