B4A Library CalculationDistanceTime - Calculate distance and time on the road

Hi all.
This is a new library to calculate the distance (kilometers or miles) and time from the source point to the point of arrival by calculating and keeping presenting the traffic and the fastest route. Of course traffic data, accidents, etc. They are calculated in real time.
You have two ways to use Google API or to use this library ( use Google API )
In this way you can get this for example:

upload_2017-7-16_10-6-38.png


Use is very simple:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim calculate As calculationdistancetime
    calculate.Initialize(41.923229,12.7241383,41.9191877,12.655384, "Km", Me, "Check_Result")

End Sub

Sub Check_Result(valore As typeLevel)
    Log("Errore: " & valore.error)
    If valore.error.Length = 0 Then
        Log("Distance: " & valore.distance)
        Log("Time to Arrive: " & valore.duration)
    End If
End Sub



The library is not free. You need to donate 10€ to get the library.
YES IS FREE :p:D:p. But anyway if you want dont forget a little Donation
 

Attachments

  • Library-CalculationDistanceTime.zip
    4.6 KB · Views: 598
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Here Rel 1.01
What's news:
1. Now you found not only log / lat but also with address example: "Via Roccafluvione n.32, 00166, Rome"
2. Language you have result in different language
3. Mode: "driving" via car (default) - "walking" via pedestrian paths and sidewalks - "bicycling" via bicycling via bicycle paths and preferred streets

Example Code B4A:
B4X:
....
Dim calculate As calculationdistancetime
'If you want to search for coordinates
calculate.Initialize("","", 41.923229,12.7241383,41.9191877,12.655384, "Km", "driving", Me, "Check_Result")
Or
'If you want to search for address
calculate.Initialize("Via Grondona n.1, 00166, Roma", "Via Roccafluvione n.32, 00132, Roma",0,0,0,0, "Km", "driving", "it", Me, "Check_Result")
....

Sub Check_Result(valore As typeLevel)
    Log("Errore: " & valore.error)
    If valore.error.Length = 0 Then
        Log("Distance: " & valore.distance)
        Log("Time to Arrive: " & valore.duration)
End If
 

Attachments

  • Library-CalculationDistanceTime1.01.zip
    5.1 KB · Views: 487

Star-Dust

Expert
Licensed User
Longtime User
Source point (coordinate) to the point of arrival (address).
Is possible?
B4X:
calculate.Initialize("",""Via Roccafluvione n.32, 00132, Roma"", 41.923229,12.7241383,0,0, "Km", "driving", Me, "Check_Result")
 
D

Deleted member 103

Guest
Hi Marco,

What Api do you use for your library, the Google Directions-Api like this?
 

DonManfred

Expert
Licensed User
Longtime User
So i dont think that know who use this
Google will know if google has served 2500 requests on a day.If it succeed then any further request is blocked (error i guess).
The only solution is to use a api key.
Then your app can use 2500 free requests "alone"...
You can also subscribe to a paid google plan with a higher quota.
 

MarcoRome

Expert
Licensed User
Longtime User
Google will know if google has served 2500 requests on a day.If it succeed then any further request is blocked (error i guess).
The only solution is to use a api key.
Then your app can use 2500 free requests "alone"...
You can also subscribe to a paid google plan with a higher quota.

Providing a key is not required for most geocoding API requests. When you do not provide a key, Google will use an IP-based quota to determine when you reach the 2,500-queries daily limit.
 

imbault

Well-Known Member
Licensed User
Longtime User
Anyway, I'm not sure a dedicated lib is very usefull for getting those Distance and Time informations from Google Api, a Class should be better for all B4X users, as it can be implemented in all environments : B4i & B4J

DistanceMatrix offers more: route optimization of x points etc...
 

MarcoRome

Expert
Licensed User
Longtime User
Anyway, I'm not sure a dedicated lib is very usefull for getting those Distance and Time informations from Google Api, a Class should be better for all B4X users, as it can be implemented in all environments : B4i & B4J

DistanceMatrix offers more: route optimization of x points etc...
Right @imbault this is good idea
 

MarcoRome

Expert
Licensed User
Longtime User
Anyway, I'm not sure a dedicated lib is very usefull for getting those Distance and Time informations from Google Api, a Class should be better for all B4X users, as it can be implemented in all environments : B4i & B4J

DistanceMatrix offers more: route optimization of x points etc...
HERE #3 you have Class
If you change the same, please share it with all community
 
Top