M
M
memradar2019-05-17 22:58:34
Delphi
memradar, 2019-05-17 22:58:34

How to convert PaintBox X and Y coordinates to Longitude and Latitude (Openstreetmap)?

Faced with an interesting problem. We have a TPaintBox component, which conditionally displays some part of the map taken from Openstreetmap. The question is how to find out the latitude and longitude when we move the cursor over this component, if we know the following:
The width and height of the TPaintBox component: hBox = 400 | wBox = 800
The current scale is known from Openstreetmap: 11
Lon and Lat for the top left point (0,0) : Lon = 28.12 | Lat = 46.07
Our cursor also moves within our TPaintBox, that is, we know the X and Y position of
OpenStreet tiles always have a length and height: 256 pxl
I would appreciate help with the formulas for the functions below, for example:
function GetLonByX( APosX: Integer): Double;
function GetLonByY(APosX: Integer): Double;
PS. Scale and initial coordinates Lon | Lat may change...
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zed, 2019-05-17
@memradar

TilesAtZoom := 1 shl Zoom; // при условии, что зум считаем с нуля
PixelsAtZoom := 256 * TilesAtZoom;

PixelResolutionLon := 360 / PixelsAtZoom;
PixelResolutionLat := 180 / PixelsAtZoom;

Lon := Lon0 + X * PixelResolutionLon;
Lat := Lat0 - Y * PixelResolutionLat;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question