如何在虚拟地球中找到鸟瞰场景的确切经/纬度坐标?
我试图在鸟瞰视图中查找地图角的纬度和经度。我希望能够在地图上绘制图钉,但我想将成千上万个地址限制为需要在地图上显示的地址。
在普通视图中,VEMap.GetMapView()。TopLeftLatLong和.BottomRightLatLong返回我需要的坐标;但在Birdseye视图中,它们返回空白(或者加密值)。 SDK建议使用VEBirdseyeScene.GetBoundingRectangle(),但这会返回距场景中心最多2英里的边界,在主要城市中,边界仍会返回太多地址。
在早期版本的VE Control中,有一个未记录的VEDecoder对象,我可以使用它来解密鸟瞰场景的LatLong值,但是该对象似乎已经消失(可能已重命名)。如何在6.1版中解码这些值?
解决方案
回答
根据http://dev.live.com/virtualearth/sdk/,这应该可以解决问题:
function GetInfo() { alert('The latitude,longitude at the center of the map is: '+map.GetCenter()); }
回答
从VEMap.GetCenter方法文档中:
This method returns null when the map style is set to VEMapStyle.Birdseye or VEMapStyle.BirdseyeHybrid.
不过,这是我发现的内容:
var northWestLL = (new _xy1).Decode(map.GetMapView().TopLeftLatLong); var southEastLL = (new _xy1).Decode(map.GetMapView().BottomRightLatLong);
(新_xy1)似乎与旧的未记录VEDecoder对象相同。
回答
这是获取地图的中心纬度/经度点的代码。此方法在"道路/空中"和"鸟眼/倾斜"地图样式中均适用。
function GetCenterLatLong() { //Check if in Birdseye or Oblique Map Style if (map.GetMapStyle() == VEMapStyle.Birdseye || map.GetMapStyle() == VEMapStyle.BirdseyeHybrid) { //IN Birdseye or Oblique Map Style //Get the BirdseyeScene being displayed var birdseyeScene = map.GetBirdseyeScene(); //Get approximate center coordinate of the map var x = birdseyeScene.GetWidth() / 2; var y = birdseyeScene.GetHeight() / 2; // Get the Lat/Long var center = birdseyeScene.PixelToLatLong(new VEPixel(x,y), map.GetZoomLevel()); // Convert the BirdseyeScene LatLong to a normal LatLong we can use return (new _xy1).Decode(center); } else { // NOT in Birdseye or Oblique Map Style return map.GetCenter(); } }
这段代码是从这里复制的:
http://pietschsoft.com/post/2008/06/Virtual-Earth-Get-Center-LatLong-When-In-Birdseye-or-Oblique-Map-Style.aspx
回答
在我看来,此问题的示例解决方案始终只能在屏幕上找到当前地图的中心,就好像总是要单击的地方一样!无论如何,我编写了这个小函数来获取我们在屏幕上单击的实际像素位置,并为此返回一个VELatLong。到目前为止,它似乎非常准确(尽管我认为这是一个大而可怕的骇客,但目前我们还没有选择余地)。
它以VEPixel作为输入,这是我们在地图上单击的位置的x和y坐标。我们可以通过传递给地图的onclick处理程序的鼠标事件来轻松地获得该信息。
function getBirdseyeViewLatLong(vePixel) { var be = map.GetBirdseyeScene(); var centrePixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel()); var currentPixelWidth = be.GetWidth(); var currentPixelHeight = be.GetHeight(); var mapDiv = document.getElementById("map"); var mapDivPixelWidth = mapDiv.offsetWidth; var mapDivPixelHeight = mapDiv.offsetHeight; var xScreenPixel = centrePixel.x - (mapDivPixelWidth / 2) + vePixel.x; var yScreenPixel = centrePixel.y - (mapDivPixelHeight / 2) + vePixel.y; var position = be.PixelToLatLong(new VEPixel(xScreenPixel, yScreenPixel), map.GetZoomLevel()) return (new _xy1).Decode(position); }
回答
Bing Maps使用条款中有趣的一点。
http://www.microsoft.com/maps/product/terms.html
鸟瞰鸟瞰航空影像的使用限制:
我们可能不会透露纬度,经度,海拔或者其他元数据;