Android Question Route between points google maps

fernando.oliboni

Active Member
Licensed User
Longtime User
I have a list of points (latitudes and longitudes) not addresses and I need to find the best route between these points. Can anyone help?
Thanks
 

aeric

Expert
Licensed User
Longtime User
B4X:
Sub btnNavPickup_Click
    Dim mapIntent As Intent
    Dim geouri As String
    
    If lblPointPickup.Text = "" Then
        Msgbox("Coordinate not set!", "E R R O R")
        Return
    End If
    geouri = "geo:?q=" & lblPointPickup.Text 'Lat & ", " & Lon
    mapIntent.Initialize(mapIntent.ACTION_VIEW, geouri)
    mapIntent.WrapAsIntentChooser("Choose app")
    StartActivity(mapIntent)
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
 
Upvote 0

emexes

Expert
Licensed User
Third idea:

http://router.project-osrm.org/route/v1/driving/145.2857,-37.8627;144.9669,-37.7072

JSON:
{"code":"Ok","routes":[{
"geometry":"z`bfFsbwuZmLjsBanA|pFmIdjAg}AaF{[email protected]@}[email protected]{[email protected]@[email protected]`_EeEfyB_Nr}@yKt[m^|[email protected]@[email protected]}@[email protected]{UkMhLiIp`[email protected]`qLoSjGsDxS}[email protected]@",
"legs":[{"steps":[],
"summary":"","weight":2610.3,"duration":2610.3,"distance":41075.4}],"weight_name":"routability","weight":2610.3,"duration":2610.3,"distance":41075.4}],
"waypoints":[{
"hint":"5lxehP___38LAAAADgAAAAAAAAAAAAAAS_p1QeKQckAAAAAAAAAAAAsAAAAOAAAAAAAAAAAAAACTLAAAQuKoCNRCvv1E4qgI1EK-_QAA_wrnJDxl","distance":0.175967,"name":"Dorset Road",
"location":[145.285698,-37.8627]},{"hint":"PACTgf___38BAAAAAgAAAAQAAAAFAAAAUSUFQBLKsD4cMXtABSexQAEAAAACAAAABAAAAAUAAACTLAAA6gSkCEmiwP30BKQIQKLA_QEA7wLnJDxl","distance":1.332309,"name":"",
"location":[144.96689,-37.707191]
}]}
 
Upvote 0

emexes

Expert
Licensed User
rsrsrsrs, ok, It's valid but that's not what I'm looking for. Obviously I need this to be automatic and in B4A

Automatic? Tick.
Can be done using B4A? Tick.

Especially useful if all you need is (approximate) time and distance of route, and then the actual routing is done by a normal GPS app or device.

{"code":"Ok","routes":[{
"geometry":"z`bfFsbwuZmLjsBanA|pFmIdjAg}AaF{[email protected]@}[email protected]{[email protected]@[email protected]`_EeEfyB_Nr}@yKt[m^|[email protected]@[email protected]}@[email protected]{UkMhLiIp`[email protected]`qLoSjGsDxS}[email protected]@",
"legs":[{"steps":[],
"summary":"","weight":2610.3,
"duration":2610.3,"distance":41075.4}],"weight_name":"routability","weight":2610.3,"duration":2610.3,"distance":41075.4}],
"waypoints":[{
"hint":"5lxehP___38LAAAADgAAAAAAAAAAAAAAS_p1QeKQckAAAAAAAAAAAAsAAAAOAAAAAAAAAAAAAACTLAAAQuKoCNRCvv1E4qgI1EK-_QAA_wrnJDxl","distance":0.175967,"name":"Dorset Road",
"location":[145.285698,-37.8627]},{"hint":"PACTgf___38BAAAAAgAAAAQAAAAFAAAAUSUFQBLKsD4cMXtABSexQAEAAAACAAAABAAAAAUAAACTLAAA6gSkCEmiwP30BKQIQKLA_QEA7wLnJDxl","distance":1.332309,"name":"",
"location":[144.96689,-37.707191]
}]}
 
Upvote 0

emexes

Expert
Licensed User
First idea was to use Google Sheets: I thought they had built-in access to Google Map functions like they do to Google Translate, but... apparently not.

Although I have a strong recollection of doing reverse geocoding perhaps 5 years ago, so... maybe it used to be possible, but got lost in a reorganisation. 🤔
 
Upvote 0

emexes

Expert
Licensed User
I wrote a TSP solver in maybe 2018 last year that, when presented with thousands of random points, would generate a path that was also a maze. Pretty sure I posted it in this forum, but do you reckon I can find it now? This post: Kids vs Travelling Salespeople (thank you @Xandoca for helping me find it)

Anyway, the algorithm was to start with an "empty" route from the starting point to the ending point (eg, from your depot departure door to your depot return arrival door), and then repeatedly choose the unvisited point furthest from points already on your route, and add them into the route at whichever position increased the route distance by the least amount.

I think it still occasionally crossed some lines, but they could be rectified with some local optimisation, or possibly a final pass that checked each combination of path segments (ie n-squared) to see if swapping the points shortened the path.
 
Last edited:
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
Does google maps itself not find the best path between these points? Does google maps not have this function of finding the best path and the shortest distance sequence?
 
Upvote 0

emexes

Expert
Licensed User
Hi, it's not a lot of points, it's 10 or 15 points, no more.

Today might be your lucky day (if your app has an internet connection) :

https://project-osrm.org/docs/v5.24.0/api/#trip-service

1667823648826.png


I am pretty sure this has been added since 2018; sure would have saved me some programming.
 
Upvote 0

emexes

Expert
Licensed User
to get the key have to pay even for few points? rsrsrsrs

Apparently $200 of monthly usage for free (although I'm not sure if that covers features like Live Traffic).

Now you can see why I'm thinking, for low-volume private use, OpenStreetmapRoutingMachine is probably a better starting point. 🍻
 
Upvote 0
Top