How to get Latitude and Longitude in Birdseye View
Posted on Monday, November 16th, 2009
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);
Categorized as bing maps