1

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

MrLister
  • 577
  • 4
  • 25
  • What is the type of `GPS`? Is it a Vector2 array? A Vector3 array? An array of type `octopus`? What kind of "point" is it? Latitude/Longitude? (X,Y)? You can sort your GPS array based on distance to origin. See this question for calculating distances: http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates – arao6 May 16 '14 at 14:52
  • Check out the Google Maps API: https://developers.google.com/maps/documentation/directions/ You can set `waypoints` for points in your `GPS` array. You can use the returned polyline to loop through the points, traveling a distance of X every iteration, and then check if `GeoCoordinate.GetDistanceTo()` < 50 for example. If it is < 50, you can add that point to `sequencedIndicies`. If you use that array as your new waypoints, Google will return a sorted array with the correct order of points. – arao6 May 17 '14 at 15:06
  • arao6 - do you have some code that I can see how to do that? ( not really familiar with google maps api ) – MrLister May 20 '14 at 16:53

1 Answers1

2

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>
MrLister
  • 577
  • 4
  • 25