PDA

View Full Version : Different results from ActiveX Control and API



micnik
10-30-2007, 08:57 AM
Hi!
I have two different applications one test-application that displays a map and another one that is just a server application.
Both have worked fine for a long time but recently I got a complaint for a calculated distance.

When I run my server application I get approx: 9.75 km.
Using the test-application I get approx: 15.7 km which seems much better.

The positions are:
Start Lat: 59.2686233333333
Long: 18.019825

Stop Lat: 59.3085966666667
Long: 18.2301466666667

Im using MapPoint 2006 (Europe)
The code for the server application looks like:

Map map = MapPointApp.ActiveMap;
map.ActiveRoute.Clear(); //clear the route if one exists
Route route = map.ActiveRoute;
route.Waypoints.Add(fromLocation, "Start");
route.Waypoints.Add(toLocation, "End");
route.Calculate();
return route.Distance;


And the code for the test-application looks like:

axMappointControl1.ActiveMap.ActiveRoute.Clear(); //clear the route if one exists
Route oRoute = axMappointControl1.ActiveMap.ActiveRoute;
oRoute.Waypoints.Add(FromLocation, "Start");
oRoute.Waypoints.Add(ToLocation, "End");
oRoute.Calculate();
axMappointControl1.ItineraryVisible = false; //hide the directions pane
MessageBox.Show(oRoute.Distance + " km");

Any help would be appreciated / Michael

Mattys Consulting
10-30-2007, 01:24 PM
Michael,

I plotted the route and got all highway 16.x km
Are the "Preferred" settings different on the machines?

Mike Mattys

micnik
10-31-2007, 02:04 AM
Hi Mike!
I'm not sure whatt settings you're referring to, but when I tried to figure out what was happening I ran both applications on the same machine.

When you say "plotted the route" I assume that you used the ActiveX control. So it seems that using that you get almost the same result as I do.

It's the other result when I'm using the "Microsoft MapPoint 13.0 Object Library (Europe)" that I get the strange distance.

Regards / Michael

Wilfried
11-01-2007, 07:43 AM
Hi,

Possible the default preferred settings are different using the object model versus the activeX control. You have to set them in both of the programs the same.

micnik
11-08-2007, 04:29 AM
Hi!
Now I understand that I misunderstood the first reply :-)

How do I check/set default preferred settings?

Thanks in advance / Michael

micnik
11-08-2007, 05:05 AM
Can this problem in any way have anything to do with the fact that I upgraded fråm version 2004 to 2006?

Regards / Michael

Eric Frost
11-08-2007, 05:20 AM
Is MapPoint 2004 still installed? Maybe when you run the ActiveX it is still opening MapPoint 2004.

Eric

micnik
11-08-2007, 05:50 AM
Hi!
No I deinstalled 2004 before installing 2006 and after reading your post I also searched my harddrive to make sure there was no old version of MappointControl.ocx laying around.

Regards / Michael

Eric Frost
11-08-2007, 06:05 AM
How do I check/set default preferred settings?

Check in the Help file, there is the PreferredRoads property of the DriverProfile object. Also, there are methods to reset the roads and PreferredSpeeds:

DriverProfile object

The DriverProfile object contains preferences for generating routes, such as travel time, methods for determining route costs, preferred roads, and so on. This object is invalidated after the map is closed.

Methods

ResetPreferredRoads
ResetSpeeds

micnik
11-08-2007, 06:19 AM
Thanks a lot!
I'll try it out and see what I can find.

Regards / Michael

micnik
11-08-2007, 07:12 AM
I just asked a friend to run the same code but on his machine that has MapPoint 2004 installed and he gets the correct distance.

So somewhere Microsoft has changed some default setting between 2004 and 2006 but only for the ApplicationClass. Drawing it onto the map still works and gives the correct distances.

This is really frustrating !!

I'll continue to look at the DriverProfile Settings.

// Michael

micnik
11-08-2007, 08:01 AM
I have now checked DriverProfile settings and on both the Control and the ApplicationClass I have the same settings for PreferredRoads (0.5 for all).

The speed is however different.
ApplicationClass:
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadArterial)); --> 34
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadInterstate)); --> 70
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadOtherHighway)); -->40

Using the Map I get:
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadArterial)); --> 55
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadInterstate)); --> 113
Debug.WriteLine(route.DriverProfile.get_Speed(GeoR oadType.geoRoadOtherHighway)); -->65

But I don't see how the speed could affect anything since my problem is that I get the how this could affect the distance.

Now I'm getting really desperate.

Any help would be really appreciated /
Michael

Eric Frost
11-08-2007, 08:19 AM
Based on the relative speeds - it might take a different path.

E.g. imagine if Arterial and OtherHighway are both 20 mph, but Interstate is 200 mph, then given a choice it will be more likely to take the Interstate even if it is a longer distance.

Could this be the explanation?

Eric

micnik
11-08-2007, 08:27 AM
Aah, I didn't think of that.

I'll try it right away and post my result here.

Thanks / Michael

micnik
11-08-2007, 08:47 AM
I'm afraid that didn't do any difference.
I set the speed to the same values, but I still get the same result.

I'm now getting lots of complaints since the upgrade.

This is really strange

What more do you nedd when calculating the distance using the object library.
I've checked the coordinates and now I've checked the DriverProfile.

The calculation looks like:
Map map = MapPointApp.ActiveMap;
map.ActiveRoute.Clear(); //clear the route if one exists
Route route = map.ActiveRoute;
route.Waypoints.Add(fromLocation, "Start");
route.Waypoints.Add(toLocation, "End");
route.Calculate();
return route.Distance;

My last try looked like this:
Map map = MapPointApp.ActiveMap;
map.ActiveRoute.Clear(); //clear the route if one exists
Route route = map.ActiveRoute;
route.Waypoints.Add(fromLocation, "Start");
route.Waypoints.Add(toLocation, "End");

route.DriverProfile.set_Speed(GeoRoadType.geoRoadA rterial, 55);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadI nterstate, 113);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadO therHighway, 65);



route.Calculate();
return route.Distance;

Regards / Michael

micnik
11-08-2007, 09:06 AM
If it's any clue. All complaints I've got so far is that the distances are now to short.

Regards / Michael

micnik
11-08-2007, 09:19 AM
Finally I figured it out.
The difference seems to be that the deafult value is now miles instead of kilometers like it was in 2004.

The strange thing was that this only seems to be the case when using the ApplicationClass and not when using the control.

map.Application.Units = GeoUnits.geoKm;

solved my problems, finally :-)

Thanks for all the help that helped in the right direction.

Regards / Michael

Eric Frost
11-08-2007, 09:22 AM
Wow good work in solving that. It didn't occur to me.. :blueeek:

micnik
11-08-2007, 09:56 AM
Thanks!
It took me a long time to find it.
Partly because I trusted the documentation that says:

Units property

Returns or sets the unit of measurement used to measure distance; similar to clicking Options on the Tools menu. Default value is geoMiles in MapPoint North America and geoKm in MapPoint Europe.

// Michael