Hi all,
I'm trying to make use of google's directions API but I am having trouble making it work.
An example of the JSON the api may return would be something as follows:
http://maps.googleapis.com/maps/api...=London&destination=Peterborough&sensor=false
Here is my best attempt at sorting the returned JSON:
Note that PO1 is a path overlay and Map1, Map2 and Map3 are used for the objects with no name.
Cheers,
Neil
I'm trying to make use of google's directions API but I am having trouble making it work.
An example of the JSON the api may return would be something as follows:
http://maps.googleapis.com/maps/api...=London&destination=Peterborough&sensor=false
Here is my best attempt at sorting the returned JSON:
B4X:
Sub JSONResponse_StreamFinish (Success As Boolean, TaskId As Int)
Dim ResponseObject As Map
ResponseObject.Initialize
Dim ResponseString As String
ResponseString=File.ReadString(File.DirInternalCache, "Directions.json")
Dim JSON As JSONParser
JSON.Initialize(ResponseString)
ResponseObject = JSON.NextObject
Dim routes As List
routes = ResponseObject.Get("routes")
Dim Map1 As Map
Map1 = routes.Get(0)
Dim legs As List
legs = Map1.Get("legs")
Dim Map2 As Map
Map2 = legs.Get(0)
Dim steps As List
steps = Map2.Get("steps")
Dim Map3 As Map
Dim StartLocation As Map
Dim EndLocation As Map
For i = 0 To steps.Size - 1
Map3 = steps.Get(i)
StartLocation = Map3.Get("start_location")
EndLocation = Map3.Get("end_location")
Dim PLat, PLon As Double
PLat = StartLocation.Get("lat")
PLon = StartLocation.Get("lon")
PO1.AddPoint(PLat, PLon)
Next
PO1.StrokeWidth = 5
PO1.Alpha = 150
Mapview1.AddOverlay(PO1)
ProgressDialogHide
End Sub
Note that PO1 is a path overlay and Map1, Map2 and Map3 are used for the objects with no name.
Cheers,
Neil