View Full Version : Driving Guidance and Segment Preference in C++

08-16-2011, 05:52 PM
Following the techniques laid out by Jonathan Oppelaar in this article Automating MapPoint in C++ With Built In GPS Features Enabled - MapPoint Articles - MP2K Magazine (http://www.mp2kmag.com/a142--project54.police.navigation.mappoint.html) I have been able to get driving guidance working for a gps navigation program using MapPoint 2010. I use a separate thread to send win api messages to MapPoint in order to manipulate the GPS pane and other controls.

What I would like to do now is set the segment preference to shortest instead of the quickest, the default . I have tried to set this in a template and have been unable to. It appears that it has to be reset any time a route is made.

loc = MapPoint->ActiveMap->GetLocation(dLat, dLong, 0);
WideString wcEnd = TEXT("End");
wayPoint = route->Waypoints->Add(loc, wcEnd.c_bstr());

/* bah! this doesn't work!!! The current GPS location is not in the
waypoint collection and it needs to be set to geoSegmentShortest. */

TVariant idx;
VariantInit( &idx );
V_VT(&idx) = VT_I4;
for (int i = 1; i <= route->Waypoints->Count; i++) {
V_I4(&idx) = i;
wayPoint = route->Waypoints->get_Item(idx);
/* the following line tells the driving guidance thread to send a win api message to the map telling it to press the "GO (f3)" button. */

I cannot find the waypoint for the GPS position in the waypoints collection. When I create a route it only shows the destination waypoint.

Has anyone been able to change the segment preference option programmatically when using driving guidance? If so, I would appreciate the assistance!

Thanks in advance!

08-18-2011, 12:04 PM
In order to get Driving Guidance to use geoSegmentShortest, I first had to create the route with my one waypoint (destination). After calling ActiveMap->GPSNavigation->Reroute() I was given a route with the current GPS location as the starting waypoint. I could then iterate over the waypoints collection and set each waypoint to geoSegmentShortest. This forces the route to be recreated using the shortest route. This causes the a flicker with the default quickest route being shown briefly then recalculated as the shortest. I don't think this is the most elegant solution but it works. I'm up for trying suggestions.