VirtualEarth: determine min/max visible latitude/longitude

1.5k Views Asked by At

Is there an easy way to determine the maximum and minimum visible latitude and longitude in a VirtualEarth map? Given that it's not a flat surface (VE uses Mercator projection it looks like) I can see the math getting fairly complicated, I figured somebody may know of a snippet to accomplish this.

2

There are 2 best solutions below

0
On BEST ANSWER

Found it! VEMap.GetMapView() returns the bounding rectangle, even works for 3D mode as well (where the boundary is not even a rectangle).

var view = map.GetMapView();

latMin = view.BottomRightLatLong.Latitude;
lonMin = view.TopLeftLatLong.Longitude;
latMax = view.TopLeftLatLong.Latitude;
lonMax = view.BottomRightLatLong.Longitude;
1
On

Using the Virtual Earth Interactive SDK, you can see how to convert a pixel point to a LatLong object:

function GetMap()
{
  map = new VEMap('myMap');
  map.LoadMap();
}

function DoPixelToLL(x, y)
{
  var ll = map.PixelToLatLong(new VEPixel(x, y)).toString()
  alert("The latitude,longitude of the pixel at (" + x + "," + y + ") is: " + ll)
}

Take a further look here: http://dev.live.com/virtualearth/sdk/ in the menu go to: Get map info --> Convert pixel to LatLong

To get the Max/Min visible LatLong's, you could call the DoPixelToLL method for each corner of the map.