Search code examples
algorithmdictionarymapscoordinate-systemscoordinate-transformation

Get the coordinates of the corners of a rectangle superimposed on a map


I'm developing an app that shows a mapview. Superimposed at this I draw a rectangle that always has the center in the screen center, therefore the center of the map. I can move a corner of the rectangle to resize it to select an area on the map.

I have only the coordinates (lat/lon) of the center of the rectangle (and of the map), the altitude and the size of the rectangle (pixel or cm).

How can I get the coordinates of the rectangle corners??

Should I calculate the scale between the size of the rectangle and the altitude of the map? and then?

please explain me this problem :)

thanks in advance


Solution

  • I found the solution. I've developed the app for BlackBerry 10 and in MapView class there are some methods that are very useful.

    Getting the coordinates of the corner of the rectangle drew on the mapview (for example to choose an area on the map)

    using

    bb::platform::geo::Point windowToWorld (const QPoint &windowCoordinates)
    

    call windowToWorld passing the coordinates of the pixel of the corners, relatively to the axis origin. The method returns the coordinates (lat/lon) of the point on the screen (x,y).

    WARNING: The origin of the window's coordinates are the upper left corner of the MapView window (not the screen), with positive values going right (x-axis) and down (y-axis).

    If you want to do the inverse use the worldToWindow method that converts world coordinates (latitude/longitude) into window coordinates (pixels).

    eg: draw a geo point on the mapview