Peter Sheats’ Blog

November 16, 2009

How to get Latitude and Longitude in Birdseye View

Filed under: bing maps — Peter Sheats @ 4:28 pm

So apparently there is a licensing issue involved in trying to get the latitude and longitude of the center of a Birdseye view when using Microsoft’s Bing maps. If your map is currently in Birdseye mode, calling map.GetCenter() will give you a VELatLong object, but if you try to access the latitude or longitude attributes on that object you won’t get anything back, since they are “protected”.

One way I’ve found to get around this is to create a new pushpin shape object with the VELatLong object returned from map.GetCenter(). Once you place that shape object on the map you can get the latitude and longitude from that shape object. If you don’t want the shape’s icon to show on the map, create a hidden ShapeLayer.

Here is the code:

    var center = new VELatLong(26.714388057589545, -80.052689909935); // West Palm Beach
    var zoom = 1;
    var map_style = VEMapStyle.BirdseyeHybrid;
    var map = new VEMap('map');
    map.LoadMap(center, zoom, map_style);
    var hidden_layer = new VEShapeLayer();
    hidden_layer.Hide();
    var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
    shape.HideIcon();
    hidden_layer.AddShape(shape);
    alert('Latitude: ' + shape.Latitude + ' Longitude: ' + shape.Longitude);

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress