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.
-
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.
Serguei : Looking at the documentation in PixelToLatLong, looks like GetMapView is what I need: To obtain the bounding area of a map in 3D mode, call the VEMap.GetMapView Method. -
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;
0 comments:
Post a Comment