Distance method

Returns the distance between two locations, in GeoUnits (miles or kilometers) as Double.

Applies to

Objects:  Map


object.Distance(StartLocation, EndLocation)


Part Description
object Required. An expression that returns a Map object.
StartLocation Required Location object. The start point of the distance to be measured.
EndLocation Required Location object. The end point of the distance to be measured.


To return the distance to a location, route, or route segment from another location, use the DistanceTo method on a Directions collection or Direction or Location object.

To return or set GeoUnits, use the Units property of an Application or MappointControl object.


    Sub ShowDistanceNYToLA()
    Dim objApp As New MapPoint.Application
    Dim objMap As MapPoint.Map
    Dim objLocNY As MapPoint.Location
    Dim objLocLA As MapPoint.Location
    Dim objCenter As MapPoint.Location
    Dim objTextbox As MapPoint.Shape

    'Set up application and create Location objects     Let objApp.Visible = True     Let objApp.UserControl = True     Set objMap = objApp.ActiveMap     Set objLocNY = objMap.FindResults("New York, NY").Item(1)     Set objLocLA = objMap.FindResults("Los Angeles, CA").Item(1)
    'Find the point on the screen midway between the two     X1% = objMap.LocationToX(objLocNY)     Y1% = objMap.LocationToY(objLocNY)     X2% = objMap.LocationToX(objLocLA)     Y2% = objMap.LocationToY(objLocLA)     x% = (X1% + X2%) / 2     y% = (Y1% + Y2%) / 2     Set objCenter = objMap.XYToLocation(x%, y%)
    'Show the distance     objMap.Shapes.AddLine objLocNY, objLocLA     Set objTextbox = objMap.Shapes.AddTextbox(objCenter, 200, 50)     Distance# = objMap.Distance(objLocNY, objLocLA)     Let objTextbox.Text = "Distance, New York to Los Angeles: " & Distance#   End Sub

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