Community of MapPoint and Bing Maps Users and Developers
This is a discussion on Handling Route that Calculates but does not Optimize within the MapPoint Desktop Discussion forums, part of the Map Forums category; MapPoint Programming Challenge Come up with the best solution and get recognition in the next newsletter as well as receive ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Handling Route that Calculates but does not Optimize Come up with the best solution and get recognition in the next newsletter as well as receive your choice of a Large MapPoint Mug or a AutoRoute 2004. ![]() Some collections of stops cannot be Optimized. If this is being done programmatically, execution hangs. A minimal example of a route that will not Optimize can be downloaded here: http://www.mp2kmag.com/downloads/florida_ptm.zip The route will calculate fine, but when you try to optimize, it returns an error "Unable to get directions from ... move one or both of the stops, and try again". Specifically, it is the route up on Hilton street that is preventing it from Optimizing, if you shift it even slightly it seems to be fine. So working Interactively, this is not really a problem. But programmatically from Excel, I am having trouble finding a way to trap for this condition. Stops can be tested and those that that are totally unroutable (stuck behind a one-way road or on a mini-road network not connected to the main road network) can be caught as an error is generated from this condition. You can then shift the individual stop's position until it works. Optimize does not generate a trappable error in the same way, it just hangs. Here's the same minimal route in Excel, the code is included below. http://www.mp2kmag.com/downloads/florida_xls.zip When you run it, you see MapPoint uses cpu for several minutes, then just gives up.. there is no error generated, it just hangs. (hit ctrl-alt-del and kill mappoint to get back to excel). How is it possible to detect this hanging or have it trigger and error and continue program execution without user intervention? Good luck! Eric Code: Private Sub CommandButton1_Click()
'This will prevent the waiting for ole application warning from popping up
Application.DisplayAlerts = False
Set oApp = CreateObject("MapPoint.Application.NA.11")
oApp.Visible = True
Set objMap = oApp.NewMap
Set objRoute = objMap.ActiveRoute
For i = 2 To 5
objRoute.WayPoints.Add objMap.GetLocation(Worksheets("Sheet1").Cells(i, 2), _
Worksheets("Sheet1").Cells(i, 3)), Worksheets("Sheet1").Cells(i, 1)
Next
Stop
'The route can be calculated i.e. all the stops are routable
objRoute.Calculate
Stop
'It is this Optimize that hangs and unfortunately doesn't generate an error trappable
'by Excel. The error only appears when working interactively with MapPoint.
objRoute.WayPoints.Optimize
'Set back to true
Application.DisplayAlerts = False
End Sub
|
| |||
| MapPoint Programming Challenge - any solutions?
Hey All, Did anybody come up with thoughts on the programming challenge? ("Some collections of stops cannot be Optimized. If this is being done programmatically, execution hangs.") I see no posts here... we'd much like some help with this one as it has us banging our heads. -Tom |
| |||
| Re: MapPoint Programming Challenge - any solutions?
Hi Tom, A workaround could be to create the mappoint component in a thread and execute it invisible. Or maybe the object model. After a certain timeout then kill the thread. However: I really dont know if the component or the object model or both are thread safe.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz www.comfortsoftware.be MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| trapping the error
I use Visual foxpro to program rather than VB, but I am sure that you have the similar error trapping code to mine. In Visual Foxpro I had a similar problem where one location in the route created the error message that Mappoint was unable to find driving directions to that point. I simply put in an "ON ERROR" snippet that allowed me to perform other logic when this happened. In my case, I was looking for distances between 2 points so my on error section changed the calculation of distances from the calculate command to the distance as the crow flies which is less accurate but still close enough for my purposes. In your case, once you trap the problem with "ON ERROR" you can perhaps put in code to look for a nearby location that is calculable. At the very least, you are not stuck in limbo. Ralph Skrzydlo www.technologix.ca |
![]() |
| Tags |
| calculates, handling, optimize, route |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Optimize and calculate a Route | rms62 | MapPoint Desktop Discussion | 2 | 08-22-2003 02:55 PM |
| Optimize a Route with Scheduled Time windows | Anonymous | MapPoint Desktop Discussion | 0 | 07-09-2003 06:20 AM |
| Calculate route with Segment preferences vs optimize | David Kachuck | MapPoint Desktop Discussion | 1 | 01-03-2003 03:29 PM |
| Route optimize: shortest vs quickest | David Kachuck | MapPoint Desktop Discussion | 1 | 12-16-2002 07:23 PM |
| I am developing a VB application which calculates .... | Anonymous | MapPoint Desktop Discussion | 2 | 04-04-2002 01:26 AM |