Share via


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

Objects:  Direction, Location

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

    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

Note  This sample code is specific for use in MapPoint North America; it is for illustration purposes only.