MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




My calculations on distance and time appear to be wrong

This is a discussion on My calculations on distance and time appear to be wrong within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hi, I'm new to the MapPoint ActiveX control and have written some code to get the distance and time betwen ...


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 Thread Tools Display Modes
  #1 (permalink)  
Old 11-27-2004
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
My calculations on distance and time appear to be wrong

Hi,

I'm new to the MapPoint ActiveX control and have written some code to get the distance and time betwen two points. But they don't match the MapPoint web service. Furthermore, they don't even match the values given by the MapPoint Windows application.

So, I obviously have some problem with the way I've written the code to extact this data from MapPoint. I've included two functions that I've coded. The first, GetDistanceAndDuration(), returns a comma delimited string like, "1.1, 4.5"; It calls GetLocationFromAddress(), which returns a location associated with a given address.

I'd really appreciate it if someone could look over my code and give me some help. I can't use MapPoint until I can figure out how to get good data from it.

Thanks,
Bob


private string GetDistanceAndDuration( string address1, string address2 )
{
string returnStr = null;
MapPoint.Route mpRoute = MpMap.ActiveRoute; // MpMap is a property of the object
mpRoute.Clear();

MapPoint.Location loc1 = GetLocationFromAddress( address1 );
mpRoute.Waypoints.Add( loc1, "loc1" );

MapPoint.Location loc2 = GetLocationFromAddress( address2 );
mpRoute.Waypoints.Add( loc2, "loc2" );

mpRoute.Calculate();

Double dElapsedTime1 = mpRoute.DrivingTime;
double duration = Math.Round( dElapsedTime1 * 24 * 60, 1 );
double distance = Math.Round( mpMap.Distance( loc1, loc2 ), 1) ;

return distance.ToString() + "," + duration.ToString();
}

private MapPoint.Location GetLocationFromAddress( string address )
{
string[] addressSplit = address.Split(new Char[] {','});
string street = addressSplit[0];
string city = addressSplit[1];
string state = addressSplit[2];

MapPoint.Map mpMap = preferences.MpMap;
MapPoint.Route mpRoute = mpMap.ActiveRoute;
MapPoint.FindResults mpFindResults;
mpFindResults = mpMap.FindAddressResults( street, city, "", state, "", 244 );

if (mpFindResults.Count >= 1)
{
mpRoute = mpMap.ActiveRoute;
IEnumerator item = mpFindResults.GetEnumerator();
item.Reset();
item.MoveNext();

return (MapPoint.Location)item.Current;
}
return null;
}
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
calculations, distance, time, wrong


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
Demographic Calculations Jim MapPoint 2006/2009 Discussion 0 12-08-2005 12:29 PM
Distance Calculations in Mappoint SiGreenwood MapPoint 2006/2009 Discussion 2 06-01-2005 10:56 PM
Automate large list of drive time & distance calculation onegalacticwino MapPoint 2006/2009 Discussion 1 12-13-2004 01:14 PM
What am i doing wrong??? alt-088 MapPoint 2006/2009 Discussion 2 09-16-2004 03:37 PM
Is Batch Process Route Calculations Possible? Anonymous MapPoint 2006/2009 Discussion 1 09-19-2002 07:30 AM


All times are GMT -5. The time now is 04:45 AM.


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

First Choice Ski Holidays
We have a vast selection of European and worldwide ski holidays available online. You can choose from First Choice ski holidays as well as packages from other big name tour operators.

Travel Specialist
Travel Counsellors is a leading travel specialist. We are a Queen's Award winning travel agency.

Holidays to Thailand
The best cultures and backgrounds make Thailand an interesting and memorable country to visit. Book great value holidays to Thailand online at dealchecker.co.uk.

Barbados Holidays
Barbados holidays can be a wonderful break from the rat race or an exciting, action packed adventure. Plan the perfect holiday in Barbados.

Balearics
Before booking to the Balearics Islands make sure you check out our travel guide online. The Balearics are renowned for their vibrant nightlife but there are also some stunning Gothic cathedrals, Stone Age ruins and fishing villages.

Family Holidays
Family holidays can be great fun. Check out your options at Travel.co.uk

Holidays in Gran Canaria
Have some fun in the sun on the Canary Islands! See On The Beach for information on holidays in Gran Canaria.


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