Search code examples
javascriptdictionarybing-mapsvirtual-earth

Get center coordinates of map


I am using VEMap API. I have the latitude and longitude of the top left point and the bottom right point (bounding box) of a map. I want to get the center point. What is an easy way to do that? I couldn't find a solution by searching on Google.

What I was thinking is that if I can define the map using the two points mentioned above, then I can get the center very easily:

// JavaScript code snippet
var center = map.GetCenter();
var lat = center.Latitude;
var lng = center.Longitude;

Is there a way to call the constructor of map object and pass the two coordinates I have?

Thanks.


Solution

  • The simple answer would be add the latitudes and divide by two, and do the same for longitudes. They are straight lines.