Convert lat / lon locations to pixel

I have a map (Mercator) and the coordinates of the four corners of the map. I need to come up with something so that I can convert the given coordinates to the corresponding points on the map. I cannot use Google or something like that, so I need to do this first.

I can use PHP or Javascript languages. I tried some things that I found in other posts, such as this one: Calculating the Mercator longitude and latitude for x and y on a cropped map (in the UK) , but I had no luck with them.

If someone can provide some help, I would be very grateful. I am terrible with math and look at some of these equations that are starting to feel out of my league, but I have to do it.

Again, thanks in advance.

+3
source share
2 answers
   function convert_coords($lat, $lon)
     {
   $width = 1281;
   $height = 1529;
// X and Y boundaries
$westLong = -75.196438;
$eastLong = -74.674072;
$northLat = 41.377581;
$southLat = 40.909232;

$lat = $lat;
$lon = $lon;

 $x = $width * (($westLong-$lon)/($westLong-$eastLong));
 $y = ($height * (($northLat-$lat)/($northLat-$southLat)));

    echo $x."<br />";
    echo $y;

}

This is what I was trying to get started. I think this is a variation of something that I shot here, but it does not give me the results that I need. I really ran into a brick wall with this bad. And there is no way on earth, I'm going to figure out the math here on my own, I tried and this is the way out of my league.

+1
source

it looks like you are working in JavaScript, in which case you should look at the version of the open source library proj4js.

, , Mercator forumla ( ), , . . , (.. )

0

Source: https://habr.com/ru/post/1759257/


All Articles