Search code examples
c#dictionarygpssequencing

Dynamically sequence GPS points along a road


I am storing GPS points along with an index -- so to reference these points in this question it will look something like this GPS[0], GPS[1], where GPS is the GPS location and [n] is the index in an array of GPS locations.

Here is how I am going to be storing the locations (in this example the array only contains 11 locations):

GPS[0] = start of road - always at first index

GPS[10] = end of road - always at last index

GPS[ 1 - 9 ] = points in between the start and end of the road

NOTE: not all of [ 1 - 9 ] points are captured at the same time for example GPS[1] and GPS[2] may be captured on Monday and GPS[3] may be captured on Wednesday and GPS[ 4 - 9 ] may be captured a month from now. If they are not captured... they are ignored.

Additionally, the GPS location may be captured "out of sequence"... what I mean by "out of sequence" is, the points are captured along the road, but not necessarily in the same order you would encounter them when you were traveling down the road from start to end.

Which leads me to questions in my algorithm :

( note 'MAP API' is any software / service that has a mapping API )

//--- is there a MAP API that does this?
Set CurrentPoint = MAP.api.FindPoint( GPSArray[0] )

//--- is there a MAP API that does this?
Set EndPoint = MAP.api.FindPoint( GPSArray[10] )

List<int> sequencedIndicies = new List<int>;   

while ( CurrentPoint != EndPoint )
{

    // Is there a MAP API that will travel down the road from the current point
    // X feet and set the current point to that location ?

    CurrentPoint = MAP.api.TravelThisManyFeetDownRoad( CurrentPoint, 100 )

    // loop through my points and check them against the current road point
    for( int i= 1; i<10; i++ )
    {
        // Is there a MAP API function will take a point, a "current" point 
        // and tell if the point is within X feet of the current point
        //
        // ( alternatively I could use Haversine function if map api does not exist ) 
        //
        if( MAP.api.IsNear( CurrentPoint, GPSArray[i],  50 ) )  <--- need this too
        {
            sequencedIndicies.Add( i );
            break;
        }
    }
}

// move the GPS points to the new sequenced order
ReindexGPSArray( GPSArray, sequenceIndicies )

I am looking for C# example code that deals with the MAP api functionality

another note... this does not require any user interface display...

I can use Lat/Lon... however, which GPS coordinates I use is not that important... what is important is the MAP api functionality that can travel down a road and determine if a point is close to the current point or not.

Thanks


Solution

  • Using Google maps API.. I figured it out:

    Here is the code:

     http://maps.googleapis.com/maps/api/directions/xml?origin=37.332829,-122.053389&destination=37.320885,-121.995869&waypoints=optimize:true|37.326531,-122.006750|37.334222,-122.037787|37.333721,-122.021086&sensor=false
    

    Here is the part of the response that orders the way points:

     <waypoint_index>1</waypoint_index>
     <waypoint_index>2</waypoint_index>
     <waypoint_index>0</waypoint_index>