red23jordan
red23jordan

Reputation: 2891

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?

Upvotes: 5

Views: 4890

Answers (1)

Ricky Bobby
Ricky Bobby

Reputation: 7618

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

Upvotes: 11

Related Questions