Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any algorithm to find the shortest path/distance in android?

I am new to android and I am doing some project planning.

To finish the planning, I have to know which algorithms or techniques that I will use in my project. The idea is very simple. I just want to determine the shortest path/distance that between my current location and few supermarkets location.

Are there any algorithms or Android API I can apply?

like image 565
red23jordan Avatar asked Oct 18 '11 06:10

red23jordan


People also ask

Which algorithm is used for finding the shortest paths?

Dijkstra's Algorithm finds the shortest path between a given node (which is called the "source node") and all other nodes in a graph.

Which is the best algorithm to find the shortest path in A graph?

Dijkstra's algorithm finds the shortest path between a node and every other node in the graph.

Which shortest path algorithm is fastest?

Dijkstra's Shortest Path Dijkstra's algorithm is used for our fastest path algorithm because it can find the shortest path between vertices in the graph. The coordinates on the arena are considered as the vertices in the graph.


1 Answers

I don't know about Android API, but if there is something you should be able to find it on google. For example try to look at "google map api", and if you can get directions and distances with the api easily.

Look for exemple at the Google direction API

Or even better : google distance matrix api it gives you the distance of any given set of points.(for example a matrix with at each row : [your position, one supermarket)

for example : if I am 20 passage de la bonne graine in paris and I want to check how far is the monoprix (supermarket 5 Rue Godefroy Cavaignac) I can request something like that : http://maps.googleapis.com/maps/api/distancematrix/json?origins=20%20passage%20de%20la%20bonne%20graine&destinations=45%20Rue%20Godefroy%20Cavaignac,%2075011%20Paris,%20France&mode=walking&language=fr-FR&sensor=false

In term of algorithm you can process as below:

create a graph:

  • each road is a edge
  • each suppermarket is a node
  • your position is a node

then apply Dijktra's algorithm to find the shortest path between your position and all supermarkets

Here is a nice illustration (from wikipedia) on how Dijktra's algorithm works :

enter image description here

hope it helps

like image 198
Ricky Bobby Avatar answered Sep 27 '22 23:09

Ricky Bobby