Share via


LocationToX method

Returns the X coordinate on the screen of the desired location. Converts map coordinates to screen coordinates (in pixels), using the Left property of the Map object as 0. A result of -1 means the desired location does not appear on the screen. Read-only Long.

Applies to

Objects:  Map

Syntax

object.LocationToX(Where)

Parameters

Part Description
object Required. An expression that returns a Map object.
Where Required Location object. Location for which coordinates are converted.

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 specifically for use in MapPoint North America; it is for illustration purposes only.