Share via


RenderServiceSoap.ConvertToLatLong Method

Converts pixel coordinates on a given map to latitude and longitude coordinates. Returns an array of LatLong[] objects from a given array of PixelCoord[] objects.

Public NotOverridable Function ConvertToLatLong ( ByVal pixels As
  [Namespace].PixelCoord(), ByVal view As
  [Namespace].MapView, ByVal width As Integer,
  ByVal height As Integer ) As [Namespace].LatLong()
    Member of [Namespace].RenderServiceSoap
[C#]
public [Namespace].LatLong[] ConvertToLatLong
  ( [Namespace].PixelCoord[] pixels ,
  [Namespace].MapView view , System.Int32 width ,
  System.Int32 height )
    Member of [Namespace].RenderServiceSoap

Parameters

  • pixels
    The array of pixel coordinates (PixelCoord[] objects) for which latitude and longitude coordinates are desired. Maximum number of coordinate pairs is 1,000.
  • view
    The defined view (MapView object) of the map image. The MapView object sent should match the one that was used to create the image.
  • width
    The width of the map image in pixels. Integer. The value should match the width dimension passed in the MapOptions.Format property used in the call that created the MapView object.
  • height
    The height of the map image in pixels. Integer. The value should match the height dimension passed in the MapOptions.Format property used in the call that created the MapView object.

Remarks

  • If you are not using the ViewByBoundingRectangle to render the map, view from any image returned from the MapPoint.BR, MapPoint.EU, MapPoint.Moon, MapPoint.NA, and MapPoint.World data sources can be used with the view parameter.
  • If the pixel coordinate is not located on the planet (for example, the map is zoomed out far enough to see the black background in the returned image and the pixel is in the background area), null is returned.
  • To convert latitude and longitude coordinates to pixel coordinates, use the ConvertToPoint method.

Example

 
[Visual Basic] 
'This example assumes that the MapPoint Web Service namespace 
'has been imported 

'Use ConvertToLatLong to allow the user to click on the map 
'and re-center the map on that point

Dim renderService As New RenderServiceSoap()

'Set up the initial view
Dim myView As New ViewByHeightWidth()
myView.CenterPoint = New LatLong()
myView.CenterPoint.Latitude = 40
myView.CenterPoint.Longitude = -120
myView.Height = 250 'PictureBox1.Size.Height
myView.Width = 250  'PictureBox1.Size.Width


Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

    ' Set the pixel coordinates to the mouse event X,Y positions.
    Dim myPixelCoords(0) As PixelCoord
    myPixelCoords(0) = New PixelCoord()
    myPixelCoords(0).X = e.X
    myPixelCoords(0).Y = e.Y
    Dim centerCoords() As LatLong
    centerCoords = renderService.ConvertToLatLong(myPixelCoords, myView, 250, 250)

    ' Set the CenterPoint property in the MapView to use the new center point
    ' that the user clicked
    myView.CenterPoint = centerCoords(0)

    Dim myPushpins(0) As Pushpin
    myPushpins(0) = New Pushpin()
    myPushpins(0).IconDataSource = "MapPoint.Icons"
    myPushpins(0).IconName = "3"
    myPushpins(0).LatLong = myView.CenterPoint
    myPushpins(0).Label = "Center"

    Dim myMapViews(0) As ViewByHeightWidth
    myMapViews(0) = myView

    Dim mapSpec As New MapSpecification()
    mapSpec.DataSourceName = "MapPoint.NA"
    mapSpec.Views = myMapViews
    mapSpec.Pushpins = myPushpins

    Dim mapImages() As MapImage
    mapImages = renderService.GetMap(mapSpec)
    PictureBox1.Image = New Bitmap(New System.IO.MemoryStream(mapImages(0).MimeData.Bits))

    ' Set the MapView variables to the view returned after re-centering.
    myMapViews(0) = mapImages(0).View.ByHeightWidth
    myView = mapImages(0).View.ByHeightWidth

End Sub

 
[C#]
//This example assumes that the MapPoint Web Service namespace 
//has been imported 

//Use ConvertToLatLong to allow the user to click on the map 
//and re-center the map on that point

RenderServiceSoap renderService  = new RenderServiceSoap();

//Set up the initial view
ViewByHeightWidth myView  = new ViewByHeightWidth();
myView.CenterPoint = new LatLong();
myView.CenterPoint.Latitude = 40;
myView.CenterPoint.Longitude = -120;
myView.Height = 250; //pictureBox1.Size.Height
myView.Width = 250;  //pictureBox1.Size.Width


private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{

    // Set the pixel coordinates to the mouse event X,Y positions.
    PixelCoord[] myPixelCoords = new PixelCoord[1];
    myPixelCoords[0] = new PixelCoord();
    myPixelCoords[0].X = e.X;
    myPixelCoords[0].Y = e.Y;
    LatLong[] centerCoords;
    centerCoords = renderService.ConvertToLatLong(myPixelCoords, myView, 250, 250);

    //Set the CenterPoint property in the MapView to use the new center point
    //that the user clicked
    myView.CenterPoint = centerCoords[0];

    Pushpin[] myPushpins = new Pushpin[1];
    myPushpins[0] = new Pushpin();
    myPushpins[0].IconDataSource = "MapPoint.Icons";
    myPushpins[0].IconName = "3";
    myPushpins[0].LatLong = myView.CenterPoint;
    myPushpins[0].Label = "Center";

    ViewByHeightWidth[] myMapViews = new ViewByHeightWidth[1];
    myMapViews[0] = myView;

    MapSpecification mapSpec  = new MapSpecification();
    mapSpec.DataSourceName = "MapPoint.NA";
    mapSpec.Views = myMapViews;
    mapSpec.Pushpins = myPushpins;

    MapImage[] mapImages;
    mapImages = renderService.GetMap(mapSpec);
    pictureBox1.Image = new Bitmap(new System.IO.MemoryStream(mapImages[0].MimeData.Bits));

    //Set the MapView variables to the view returned after re-centering.
    myMapViews[0] = mapImages[0].View.ByHeightWidth;
    myView = mapImages[0].View.ByHeightWidth;

}

 

See Also

RenderServiceSoap Class | LatLong Class | PixelCoord Class | MapView Class | MapOptions.Format Class | Client-Side Point to Latitude/Longitude Conversion Sample | RenderServiceSoap.ConvertToPoint Method