> Can you suggest me a way?
> 
> > For a nice overview of all this see e.g.
> > https://kartoweb.itc.nl/geometrics
> 
> I think, I don't have the needed mathematical knowledge to understand that...
> :(
> 
> I try to explain again what I need...
> I created an image, putting more tiles together. This is a PNG.
> Then I try to add some markers (airports) at known coordinates. And I need to
> convert this coordinates in X,Y related to my image.
> I searched many procedures in Internet, but they always position the markers
> at the wrong place.
> I tried now a very simple procedure that assumes Earth is flat, but it does 
> not
> work correctly, too...
> 
> This is my code (PHP):
> 
> function latlngToScreenXY($lat, $lng, $minLat, $minLng, $maxLat, $maxLng,
> $mapWidth, $mapHeight) {
>    $lngDelta = $maxLng - $minLng;
>    $relLng = $lng - $minLng;
>    $percLng = $relLng / $lngDelta;
>    $x = $mapWidth * $percLng;
> 
>    $latDelta = $maxLat - $minLat;
>    $relLat = $lat - $minLat;
>    $percLat = $relLat / $latDelta;
>    $y = $mapWidth * $percLat;
> 
>    return array('X' => $x, 'Y' => $mapHeight - $y); }
> 
> You can see the result as attachment.
> In the Map I drawed two circles: the first one at the south-west corner of the
> map. This is correct.
> The second one should be in the middle of the map ( ($maxLat - $minLat) / 2 +
> $minLat, ($maxLng - $minLng) / 2 + $minLng ), and you see, this is NOT
> correct.
> Finally I tried to add the markers for the airports of Kamenz and Bautzen. And
> they are on the wrong position (both are souther than the correct position,
> Kamenz is wester and Bautzen is easter, too).
> 
> Can you please send me at least a pseudocode to understand you to convert
> LatLng to Y,X of an image?
> 

Ah so you are trying to convert long lat to pixel coordinates.
What mapping software are you using to draw your maps?

This kind of transformation is often built into the mapping library you are 
using and is very particular to the mapping library, zoom etc., page buffering 
is all handled internally.

This is also often done in javascript, where you take initial coordinates of 
user perhaps in PHP to render the initial map and then thenceforward you do 
ajax calls as 
Needed to feed data back to your php

Here is an example using MapLibre

https://maplibre.org/maplibre-gl-js/docs/examples/get-coordinates-of-the-mouse-pointer/








Reply via email to