Share via


XYToLocation method

Returns the Location object for the specified screen coordinates.

Applies to

Objects:  Map

Syntax

object.XYToLocation(X, Y)

Parameters

Part Description
object Required. An expression that returns a Map object.
X Required Long. The X coordinate of the desired location on the screen, in pixels.
Y Required Long. The Y coordinate of the desired location on the screen, in pixels.

Example

    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.