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:
How do I modify this code to get the driving distance of the 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;
TIA