Android Question Use the calculate button to retrieve information from the website

Isac

Active Member
Licensed User
Longtime User
Hi everyone,
I would like to create an application where I set the destination and arrival, and through this website I recover the cost of motorway tolls.
it's possible?

this is the website:

thank you
 

msmerce

Member
Licensed User
Longtime User
If you take a closer look at the website, you will notice that the website first uses the TomTom api to calculate the route and then sends the route to its own api. I have attached an example below that calculates the costs from the coordinates of the starting point and destination. You may have to convert the input into coordinates.

Example:
'    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
 
Upvote 0
Top