Johnson
Johnson

Reputation: 55

Dynamically creating a road map

How do I go about creating a dynamic road map, that will be capable of implementing algorithms to calculate suggested directions like any GPS system would?

The things I have thought about so far:

  1. Creating a class Road that stores data like: List of Long- and Latitude coordinates and connected roads (e.g. A coordinate + the id of another Road that is connected on this coordinate).

  2. Drawing the roads with Polyline from the Long- and Latitude coordinates stored in road objects

  3. How the algorithm to iterate through the roads should look like, to prevent endless loops of attempts to find the "best" road direction. (Any suggestions or references?)

  4. A better way to track current location than Geolocation (I have yet to test it on a Phone device, but it was very inaccurate when tested on my laptop here at home)

As to the four points above, I am unsure if this is the right way to go on about this system.

I would really appreciate some input on the Road class that i mean to create. It is the only way i could think of that "might" work, when trying to iterate through the roads to find a suggested direction from Point A to Point B. Also if it is, should I store a reference to another road (id) + the coordinate of where the roads cross?

Upvotes: 0

Views: 864

Answers (1)

weston
weston

Reputation: 54801

Look at Dijkstra's algorithm.

The language used is a bit different:

  • Your Roads are Edges.
  • Your Roads are joined by Vertices or Nodes.
  • The Map is known as a Graph.

Note that the algorithm doesn't care about where the roads are, no need for lat-long other than for your drawing. It just needs a cost for traveling, i.e. distance or time, but the article/algorithm refers to this as distance.

Upvotes: 1

Related Questions