none
Get center coordinates of map RRS feed

  • Question

  • 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.

    Monday, September 17, 2012 3:09 PM

Answers

  • The simple answer would be add the latitudes and divide by two, and do the same for longitudes. They are straight lines.
    • Marked as answer by mfghazi Monday, September 17, 2012 4:59 PM
    Monday, September 17, 2012 4:59 PM

All replies

  • Yes. You can create a VELatLongRectangle and pass it into the map.SetMapView method: http://msdn.microsoft.com/en-us/library/bb429594.aspx

    That said you should not be doing any new development against the Bing Maps V6.3 control. This is a very old control. All new development should be done with the Bing Maps V7 AJAX control. Documentation can be found here: http://msdn.microsoft.com/en-us/library/gg427610.aspx


    http://rbrundritt.wordpress.com

    Monday, September 17, 2012 3:17 PM
  • Thanks Richard.

    Yes, we are planning to move to v7 shortly.

    The issue is that the coordinates are coming from database. I get the center (using code mentioned) and then I display it. I have tried the method you mentioned, but for that, it requires the control name when you call the construction for a new VEMap.

    Monday, September 17, 2012 3:33 PM
  • Let me rephrase.

    I have an object VELatLongRectangle and I want to know coordinates for its center. I don't want or have an object of VEMap in scope.

    Please help.

    Monday, September 17, 2012 3:56 PM
  • The simple answer would be add the latitudes and divide by two, and do the same for longitudes. They are straight lines.
    • Marked as answer by mfghazi Monday, September 17, 2012 4:59 PM
    Monday, September 17, 2012 4:59 PM