' Manifest:
' CreateResourceFromFile(Macro, Core.NetworkClearText)
' Main:
Dim lat_start As String = "46.018734"
Dim lon_start As String = "12.2866955"
Dim lat_destination As String = "44.14312"
Dim lon_destination As String = "11.16431"
Dim m As Map
m.Initialize
m.Put("key", "zo1NVeRfNSlT15rgiGYBfVogq7GLEPoW") ' Please check if you are allowed to use this key for the TomTom API.
m.Put("routeType", "fastest")
m.Put("traffic", "true")
m.Put("travelMode", "car")
m.Put("vehicleMaxSpeed", "0")
m.Put("vehicleWeight", "0")
m.Put("vehicleAxleWeight", "0")
m.Put("vehicleLength", "0")
m.Put("vehicleWidth", "0")
m.Put("vehicleHeight", "0")
m.Put("vehicleCommercial", "false")
m.Put("maxAlternatives", "1")
m.Put("instructionsType", "text")
m.Put("language", "de-DE") 'or "it-IT"
Dim coor As String = lat_start & "," & lon_start & ":" & lat_destination & "," & lon_destination
Dim json As String
For Each key As String In m.Keys
If json.Length <> 0 Then json = json & "&"
json = json & key & "=" & m.Get(key)
Next
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://api.tomtom.com/routing/1/calculateRoute/" & coor & "/json?" & json)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim root As Map = jp.NextObject
Dim routes As List = root.Get("routes")
Dim myroute As Map = routes.Get(0)
Dim legs As List = myroute.Get("legs")
Dim mylegs As Map = legs.Get(0)
Dim points As List = mylegs.Get("points")
Dim mypoints As List
mypoints.Initialize
For Each p As Map In points
mypoints.Add(CreateMap("lat": p.Get("latitude"), "lng": p.Get("longitude")))
Next
Dim m1 As Map
m1.Initialize
m1.Put("caselli", True)
m1.Put("pedaggio", True)
m1.Put("ads", False)
m1.Put("percorso", mypoints)
Dim jg As JSONGenerator
jg.Initialize(m1)
j.PostString("http://www.autostrade.it/autostrade-gis/postBridge", jg.ToString)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim jp1 As JSONParser
jp1.Initialize(j.GetString)
Dim root1 As List = jp1.NextArray
Dim sum As Double
For Each mx As Map In root1
If mx.ContainsKey("toll") Then
Dim mx2 As Map = mx.Get("toll")
sum = sum + mx2.Get("clsA")
End If
Next
Log("cost: " & sum)
End If
End If
j.Release