0

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.

Farhan
  • 2,535
  • 4
  • 32
  • 54

2 Answers2

0

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

Farhan
  • 2,535
  • 4
  • 32
  • 54
  • 1
    watch out - they could cross the 180° line – Bergi Sep 17 '12 at 18:20
  • Theoretically yes, but I am only working with countries where they don't. – Farhan Sep 17 '12 at 19:05
  • @Bergi, can you please answer my question on the top of this page? I came up with a workaround which works perfectly in my scenario. There won't be ANY cases in which it won't. How is that bad code? When someone is making a simple application to show time on a watch, will one handle a situation where minutes and hours can be in millions or billions? – Farhan Sep 18 '12 at 01:58
  • No, but his application should be open to show different timezones, even if he is going to ship it only to one country :-) – Bergi Sep 18 '12 at 08:54
0

Is there any reason you can't use the VEMap.GetCenter method after the map has been constructed? This way regardless of the viewpoint it will be correct. If you're using the default constructor you can pass in your bounding box, and then call getmap after the object is instantiated.

http://msdn.microsoft.com/en-us/library/bb412539.aspx

iivel
  • 2,576
  • 22
  • 19