views:

1085

answers:

5

I'm trying to find the latitude and longitude of the corners of my map while in birdseye view. I want to be able to plot pins on the map, but I have hundreds of thousands of addresses that I want to be able to limit to the ones that need to show on the map.

In normal view, VEMap.GetMapView().TopLeftLatLong and .BottomRightLatLong return the coordinates I need; but in Birdseye view they return blank (or encrypted values). The SDK recommends using VEBirdseyeScene.GetBoundingRectangle(), but this returns bounds of up to two miles from the center of my scene which in major cities still returns way too many addresses.

In previous versions of the VE Control, there was an undocumented VEDecoder object I could use to decrypt the LatLong values for the birdseye scenes, but this object seems to have disappeared (probably been renamed). How can I decode these values in version 6.1?

A: 

According to http://dev.live.com/virtualearth/sdk/ this should do the trick:

function GetInfo()
{ alert('The latitude,longitude at the center of the map is: '+map.GetCenter());
}

MartinHN
+1  A: 

From the VEMap.GetCenter Method documentation:

This method returns null when the map style is set to VEMapStyle.Birdseye or VEMapStyle.BirdseyeHybrid.

Here is what I've found, though:

var northWestLL = (new _xy1).Decode(map.GetMapView().TopLeftLatLong);
var southEastLL = (new _xy1).Decode(map.GetMapView().BottomRightLatLong);

The (new _xy1) seems to work the same as the old undocumented VEDecoder object.

Soldarnal
+2  A: 

Here's the code for getting the Center Lat/Long point of the map. This method works in both Road/Aerial and Birdseye/Oblique map styles.

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();
            }
        }

This code was copied from here: http://pietschsoft.com/post/2008/06/Virtual-Earth-Get-Center-LatLong-When-In-Birdseye-or-Oblique-Map-Style.aspx

Chris Pietschmann
+2  A: 

It always seems to me that the example solutions for this issue only find the centre of the current map on the screen, as if that is always the place you're going to click! Anyway, I wrote this little function to get the actual pixel location that you clicked on the screen and return a VELatLong for that. So far it seems pretty accurate (even though I see this as one big, horrible hack - but it's not like we have a choice at the moment).

It takes a VEPixel as input, which is the x and y coordinates of where you clicked on the map. You can get that easily enough on the mouse event passed to the onclick handler for the map.

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);
}
Jason
A: 

An interesting point in the Bing Maps Terms of Use.. http://www.microsoft.com/maps/product/terms.html

Restriction on use of Bird’s eye aerial imagery: You may not reveal latitude, longitude, altitude or other metadata;

itchi