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

  [Microsoft Visual Basic 6.0]
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
[C#]
void ShowDistanceNYtoLA() { ApplicationClass objApp = null; MapPoint.Map objMap; MapPoint.Shape objTextBox; String Place1 = "New York, NY"; String Place2 = "Los Angeles,CA"; double Distance; //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 obNY = objMap.FindResults(Place1); MapPoint.FindResults obLA= objMap.FindResults(Place2); MapPoint.Location objNY = obNY.get_Item(ref Item) as MapPoint.Location; MapPoint.Location objLA = obLA.get_Item(ref Item) as MapPoint.Location; objNY.GoTo(); objLA.GoTo(); MapPoint.SelectedArea sa = objMap.SelectedArea; MapPoint.Location objCenter = objMap.XYToLocation(sa.Left + sa.Width, sa.Top + sa.Height); objMap.Shapes.AddShape(MapPoint.GeoAutoShapeType.geoShapeOval, objLA, 50, 30); objMap.Shapes.AddLine(objNY.Location, objLA.Location); Distance = objMap.Distance(objNY, objLA); objTextBox = objMap.Shapes.AddTextbox(objCenter, 100, 50); objTextBox.Text = ("Distance, NY to LA: " + Distance); objMap.Altitude = 350; }

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