dawa
01-04-2006, 11:47 AM
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:
try{
if (this.mappointApplication == null) throw new Exception("Failed to create an object instance of MapPoint.MappointControlClass()");
MapPoint.FindResults loResultsFrom = this.mappointApplication.ActiveMap.FindAddressResu lts(
stringFromAddress,
stringFromCity,
stringFromOtherCity,
stringFromRegion,
stringFromPostalCode,
stringFromCountry);
if (loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoAllResultsValid ||
loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoFirstResultGood)
{
MapPoint.FindResults loResultsTo = this.mappointApplication.ActiveMap.FindAddressResu lts(
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
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:
try{
if (this.mappointApplication == null) throw new Exception("Failed to create an object instance of MapPoint.MappointControlClass()");
MapPoint.FindResults loResultsFrom = this.mappointApplication.ActiveMap.FindAddressResu lts(
stringFromAddress,
stringFromCity,
stringFromOtherCity,
stringFromRegion,
stringFromPostalCode,
stringFromCountry);
if (loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoAllResultsValid ||
loResultsFrom.ResultsQuality == MapPoint.GeoFindResultsQuality.geoFirstResultGood)
{
MapPoint.FindResults loResultsTo = this.mappointApplication.ActiveMap.FindAddressResu lts(
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