MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




How do I get the driving distance of two addresses?

This is a discussion on How do I get the driving distance of two addresses? within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; How do I get the driving distance of two addresses using MapPoint 2004 COM Interface in C#.NET? I have already ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 01-04-2006
Junior Member
White Belt
 
Join Date: Jan 2006
Posts: 4
How do I get the driving distance of two addresses?

How do I get the driving distance of two addresses using MapPoint 2004 COM Interface in C#.NET?

I have already added the reference to MapPoint COM inteface to the project.

Below is my code which retrieves the distance (NOT Driving distance) between two locations:
Code:
        try{
            if (this.mappointApplication == null) throw new Exception("Failed to create an object instance of MapPoint.MappointControlClass()");
            MapPoint.FindResults loResultsFrom = this.mappointApplication.ActiveMap.FindAddressResults(
                stringFromAddress,
                stringFromCity,
                stringFromOtherCity,
                stringFromRegion,
                stringFromPostalCode,
                stringFromCountry);
            if (loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoAllResultsValid ||
                loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoFirstResultGood)
            {
                MapPoint.FindResults loResultsTo = this.mappointApplication.ActiveMap.FindAddressResults(
                    stringToAddress,
                    stringToCity,
                    stringToOtherCity,
                    stringToRegion,
                    stringToPostalCode,
                    stringToCountry);
                if (loResultsTo.ResultsQuality == MapPoint.GeoFindResultsQuality.geoAllResultsValid ||
                    loResultsTo.ResultsQuality == MapPoint.GeoFindResultsQuality.geoFirstResultGood)
                {
                    object index = 1;
                    MapPoint.Location loFrom = (MapPoint.Location)loResultsFrom.get_Item(ref index);
                    MapPoint.Location loTo = (MapPoint.Location)loResultsTo.get_Item(ref index);
                    ldDistance = loTo.DistanceTo(loFrom);
                }
                else
                {
                    throw new Exception("To address is not a valid one. Result Quality: " + loResultsTo.ResultsQuality.ToString());
                }
            }
            else
            {
                throw new Exception("From address is not a valid one. Result Quality: " + loResultsFrom.ResultsQuality.ToString());
            }
        }
        catch (Exception loExp)
        {
            string lcMessage = loExp.Message + ((char)13).ToString()
                            + loExp.Source + ((char)13).ToString()
                            + loExp.StackTrace + ((char)13).ToString()
                            + loExp.Source + ((char)13).ToString();
            EventLog.WriteLog(loExp);
            while (loExp.InnerException != null)
            {
                EventLog.WriteLog(loExp);
            }
        }
        return ldDistance;
How do I modify this code to get the driving distance of the two locations?

TIA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-08-2006
Junior Member
Yellow Belt
 
Join Date: Jan 2003
Posts: 17
Send a message via ICQ to brianmcg
Hi Dawa,

Your code is calculating the great circle distance between the two points, but to get MapPoint to tell you the driving distance, you'll have to get it to calculate the route between the two points first.

After you create the location objects using FindAddressResults() method, use the ActiveMap.ActiveRoute.Waypoints.Add method to add these locations to the route, then call the .Calculate method to do all the calculations.

The VB example here gets the route distance and the route time (based on the default driving speeds) between your two location objects (loFrom and loTo).

Hope this helps.

Code:
        map.ActiveMap.ActiveRoute.Clear
        map.ActiveMap.ActiveRoute.Waypoints.Add loFrom
        map.ActiveMap.ActiveRoute.Waypoints.Add loTo
        
        map.ActiveMap.ActiveRoute.Calculate
        
        nRouteDistance = map.ActiveMap.ActiveRoute.Distance
        nRouteTime = map.ActiveMap.ActiveRoute.DrivingTime * 24 * 60     '   convert to minutes
        
        map.ActiveMap.ActiveRoute.Clear
__________________
Brian McGrath
CAD North Inc.
http://www.cadnorth.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008
Junior Member
White Belt
 
Join Date: Nov 2006
Posts: 2
Re: How do I get the driving distance of two addresses?

Am new to vba but would like to do what you've done here? Can anyone give me an idiots guide?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 04-16-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,112
Re: How do I get the driving distance of two addresses?

Hi,

It looks you use the object model. Converting from VB to C# is only a little syntax difference. Something like this should work for you:

Code:
MapPoint.ActiveRoute.Clear;
MapPoint.ActiveRoute.Waypoints.Add(loFrom);
MapPoint.ActiveRoute.Waypoints.Add(locTo);
MapPoint.ActiveRoute.Calculate();
double RouteDistance = MapPoint.ActiveRoute.Distance;
double RouteTime = MapPoint.ActiveRoute.DrivingTime * 24 * 60;
MapPoint.ActiveRoute.Clear();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 04-16-2008
Junior Member
White Belt
 
Join Date: Nov 2006
Posts: 2
Re: How do I get the driving distance of two addresses?

Thank you for your reply. I've only ever used vba for excel macros- I could do with an idiots guide. Any chance you could brek it down for me? How do I create an object model? Sorry to be a pain! I would be very grateful
Kind regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 04-18-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,112
Re: How do I get the driving distance of two addresses?

Hi,

You use the object model witch is using the type library and another way is to use the activex component. The ActiveMap property of the control is the mapoint object.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
addresses, distance, driving


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/how-do-i-get-driving-distance-two-addresses-4692.html

Posted By For Type Date
seattle-tacoma forums - craigslist This thread Refback 12-19-2007 07:30 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Find distance between two addresses WonderMonkey MapPoint 2006/2009 Discussion 0 06-26-2006 03:28 PM
Driving distance between two postcodes zippy MapPoint 2006/2009 Discussion 2 10-24-2004 11:56 PM
Fast Calculation of Driving Distance between 2 points Bob Chase Wish List 6 08-19-2004 07:10 PM
SHORTEST DRIVING DISTANCE Anonymous MapPoint Web Service and Virtual Earth 1 07-29-2004 08:51 PM
Calculate Distance Between 2 Street Addresses? Anonymous MapPoint 2006/2009 Discussion 4 10-08-2003 06:16 AM


All times are GMT -5. The time now is 03:25 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54