View Full Version : Extracting waypoint information from a mappoint route object

03-14-2012, 01:50 PM

Sorry if this has been asked before (I'm sure it probably has) but I'm not exactly sure what it is I'm looking for.

What I'm trying to do is feed in a list of postcodes to mappoint and optimise the route and get back the optimised route. This is all being done in C# (.Net 2010) with the application.visible = false. I never want to actually see MapPoint (I'm using MapPoint 2010 as well).

It would appear that I can create an instance of MapPoint, load in the way points and then optimise the route.

The problem that I have is getting the optimised route back out of the route object.

My code thus far

MapPoint.Application mp;
MapPoint.Map map;
MapPoint.Route mpr;
phpostcode.Results mresults;

public void show_MapPoint(List<string> joblist)
mp = new MapPoint.Application();
mp.Visible = false;
map = mp.ActiveMap;
mpr = map.ActiveRoute;

map.Parent.PaneState = MapPoint.GeoPaneState.geoPaneRoutePlanner;

foreach (string row in joblist)
phpostcode.Results.AddressDetailsDataTable full_address = this.ValidatePostcodeAFD(row.Trim().Replace(" ", ""));
mpr.Waypoints.Add(map.FindAddressResults(full_addr ess[0].Street, full_address[0].Town, "", full_address[0].County, full_address[0].Postcode, "GB")[1]);


public void getRouteOrder()
mpr = mp.ActiveMap.ActiveRoute;

//for (int i = 0; i < mpr.Directions.Count; i++)
// string aaa;
// aaa = mpr.Waypoints.dir

First the show_MapPoint() is called, then the getRouteOrder()

While digging around on the net, apparently you can iterate through the mpr object, as you can see by my attempt with the for loop above. However, I am not getting an integer back from the mpr.Directions.Count, just some error message, Member 'Directions' on embedded interop type 'MapPoint.Route' cannot be evaluated while debugging since it is never referenced in the program. Consider casting the source object to type 'dynamic' first or building with the 'Embed Interop Types' property set to false when debugging

Yet when I drill down on the object in the debugger I can clearly see in a "Dynamic" section that there are indeed 14 postcodes/waypoints present - the same as I passed in.

Basically what I want to do is -

Feed mappoint a list of postcodes
Optimise the postcode route
get back in .Net the newly ordered list of postcodes

Can anyone be of any help here. I'm totally new to mappoint (about 3 hours experience) but been coding for 15+ years. If anyone has any example code that may be of use to me that would be great, I dont mind what language it is - I think anything would be of help to me at the moment.