'origin or destination parameter can be placeID (pefixed by place_id:) or Lat,Lon
'origin =place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE
'destination=41.43206,-81.38992
Public Sub GetRoutePolyPointsString(origin As String, destination As String) As ResumableSub
Dim polyPoints As String
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("https://maps.googleapis.com/maps/api/directions/json", Array As String("origin", origin, "destination", destination,"key",GoogleApiKey))
'...............................................
Sub GetTripDistanceData(source As String, destination As String) As ResumableSub
Dim travelduration, traveldistance As Int
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("https://maps.googleapis.com/maps/api/directions/json", Array As String("origin", source,"destination", destination,"key", GoogleApiKey))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim mapRoot As Map = parser.NextObject
If mapRoot.Get("status") = "OK" Then
Dim lstRoutes As List = mapRoot.Get("routes")
For Each mapRoutes As Map In lstRoutes
Dim lstLegs As List = mapRoutes.Get("legs")
For Each mapLegs As Map In lstLegs
'start_address = mLegs.Get("start_address")
'end_address = mLegs.Get("end_address")
Dim lstSteps As List = mapLegs.Get("steps")
For Each mapSteps As Map In lstSteps
Dim mapDuration As Map = mapSteps.Get("duration")
travelduration = travelduration + mapDuration.Get("value") 'as Meters
Dim mapDistance As Map = mapSteps.Get("distance")
traveldistance = traveldistance + mapDistance.Get("value") 'as Seconds
Next
Next
Next
Dim TripDistance As TripDistanceType
TripDistance.TravelDistance = traveldistance
TripDistance.TravelDuration = travelduration
Return TripDistance
Else
Log("Error: " & mapRoot.Get("status"))
End If
Else
Log("Error!")
End If
j.Release
End Sub