saving mappoint route in a file

giaarcix
08-30-2006, 10:27 AM
Hello,
what I'm trying to do is to create a route with mappoint and then to save it in a file.
My program should be able to build some routes for different cars, and this part is ok.
Then I need to save all the routes somewhere in my pc, so that I'll be able to pick a car and to see the relative route.
But I don't need an image of the route: I need an object witch I can use in my code. Is this possible?
I hope I've been clear..... Thank you very much,

Giacomo from Italy

Wilfried
08-30-2006, 02:01 PM
Hi,

Yes easy to do:

for (int i = 0; i < route.Directions.Count; i++) {
object o = i;
MapPoint.Direction direction = route.Directions.get_Item(ref o);
// here you have each direction with all his properties
}

You cannot use foreach because foreach is not in the right sequence !

giaarcix
09-26-2006, 05:42 AM
Hi,
I'm back on the problem. Actually I am writing code in Visual Basic on Mappoint 2006.
To save the route I did so:

For i = 1 To objRoute.Directions.Count
Set objLoc = objRoute.Directions.Item(i).Location
coordinates = get_coordinates_from_objloc(objLoc) 'My routine
Call save_coordinates(coordinates, "my_car") 'My routine
Next

I create an objLoc for each direction into the objRoute, I find the coordinates of every objLoc and I save them into a text file so that when I quit the program I have still saved into my computer the route.
BUT: is there another way to do this? It seems to me to be a so long process if the route is very long... and I'm not sure that my routine get_coordinates_from_objloc(objLoc) works perfectly! :-(
Isn't there a way to save the objRoute directly into a file?
Thank you so much!

Giacomo from Italy

Wilfried
09-26-2006, 01:47 PM
Hi,

As far as I know there is no other way. But I think this way will be fast, and you must be sure that your get_coordinates_from_objloc(objLoc) works perfecly :)

giaarcix
09-27-2006, 09:20 AM
Thank you.. actually I've just realized that the bug is not into my function get_coordinates_from_objloc(objLoc)! It seems to be into the objRoute.Directions!
Try running this code (this time on Mappoint2004, actually I can't try on 2006).
You'll see that the route is well calculated beetween Milan and Rome, but when I cicle on the directions not all the waypoints are the right ones.
Is there something wrong in my code (where???), or, as I believe, there is bug in Mappoint?

Private Sub Form_Load()

Dim objMap As MapPointctl.Map
Dim objLoc1 As MapPointctl.Location
Dim objLoc2 As MapPointctl.Location
Dim objLoc3 As MapPointctl.Location
Dim objpushpin As MapPointctl.Pushpin

MappointControl1.NewMap geoMapEurope

Set objMap = MappointControl1.ActiveMap

Set objMap = MappointControl1.ActiveMap
Set objRoute = objMap.ActiveRoute

Set objLoc1 = objMap.FindResults("Milan")(1)
Set objLoc2 = objMap.FindResults("Rome")(1)

objRoute.Waypoints.Add objLoc1
objRoute.Waypoints.Add objLoc2

objRoute.Calculate
MappointControl1.ItineraryVisible = False

For i = 1 To objRoute.Directions.Count
Set objLoc3 = objRoute.Directions.Item(i).Location

Set objpushpin = objMap.AddPushpin(objLoc3)
objpushpin.Highlight = True
objLoc3.GoTo

Next

End Sub

Wilfried
09-28-2006, 08:10 AM
Hi,

You have to check if the given item is indeed a waypoint.
In C# it is something like this:

for (int i = 1; i <= route.Directions.Count; i++) {
o = i;
object wp = route.Directions.get_Item(ref o) as Waypoint;
if (wp == null)
continue;
// and here the rest of your code

Should be something similar in VB, but if I try to do it I will type more syntax errors and confuse everyone including myself :)

I tryed it out and the strange pushpins (one even 15 km of the route) are away now :)

 
Web mp2kmag.com
mapforums.com