View Single Post
Old 04-06-2007, 03:58 PM   #5
RickS
Low Bitrate
 
RickS's Avatar
 
Join Date: Nov 2005
Location: Bethesda, MD
Posts: 86
You've found one of the main problems with trying to build a car based, real-time GPS application with MP. MP cannot internally tell you if a location or pushpin is located on a route...you have to do it through educated guessing and error checking to see if your guess was correct.

The following will tell you how much straight line distance is left from your current location (based on CurrentLatitude and CurrentLongitude) to an item in your directions collection (the route). When the distance gets to be less than some threshold you determine (I set it at <0.015), you can increment to the next item in the directions collection and most of the time it'll work.

DistanceToNextAction = objRoute.Directions.Item(CurrentInstructionNumber) .DistanceTo(objMap.GetLocation(CurrentLatitude, CurrentLongitude))
If DistancetoNextAction < 0.015 Then
CurrentInstructionNumber += 1
End If

Sometimes it won't work which is where you have to setup some error checking to see if the distance gets progressively greater from your next direction item (that usually indicates you've got something wrong).

Another thing I started working on, but haven't had a chance to finalize though it should work pretty well, is to get the name of the street you are currently on and iterate through the direction items to get a match. That'll tell you which direction item you are on then you can use the technique above to change to the next direction when you get to the "turn"
RickS is offline   Reply With Quote