DistanceTo method
Returns the distance to a location, route, or route segment from another location, in GeoUnits (miles or kilometers) as Double.
Applies to
Collections: Directions
Syntax
object.DistanceTo(From)
Parameters
Part |
Description |
---|---|
object |
Required. An expression that returns a collection or object from the Applies to list. |
From |
Required Location object. Location representing the place from which you want to measure. |
Remarks
To return the distance between two locations, you may also use the Distance method on a Map object.
To return or set GeoUnits, use the Units property of an Application or MappointControl object.
Example
[Microsoft Visual Basic 6.0]
Sub LocationToLocationDistance()
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc As MapPoint.Location
'Set up application
Set objMap = objApp.ActiveMap
objApp.Visible = True
objApp.UserControl = True
'Get a location on the map
Set objLoc = objMap.FindResults("Seattle, WA")(1)
'Find the distance to 0,0 from that location
MsgBox "Distance from location to 0,0: " + _
CStr(objLoc.DistanceTo(objMap.GetLocation(0, 0)))
End Sub
[C#]
void ZoomtoLocation()
{
//Define an application instance
ApplicationClass objApp = null;
MapPoint.Map objMap;
String Place1 = "New York, NY";
//Create an application class instance
objApp = new ApplicationClass();
//Set up application
objApp.Visible = true;
objApp.UserControl = true;
objMap = objApp.ActiveMap;
object Item = 1;
MapPoint.FindResults obLoc = objMap.FindResults(Place1);
MapPoint.Location objLoc = obLoc.get_Item(ref Item) as MapPoint.Location;
objLoc.GoTo();
System.Windows.Forms.MessageBox.Show("The Distance from location to 0.0: " + (System.Math.Round((objLoc.DistanceTo(objMap.GetLocation(0,0,100))),2)));
}
Note This sample code is specifically for use in MapPoint North America; it is for illustration purposes only.