Search code examples
javascriptgeolocationprojection

Given an image of a map convert an x and y coordinate to Latitude and Longitude


I have an image of a Mercator map (4000px by 2828px). I know that the longitude on the left is -170, the longitude on the right is 190, and the latitude on the bottom is 85.

I'm able to calculate the x and y given a latitude and longitude from the solution at Mercator longitude and latitude calculations to x and y on a cropped map (of the UK). However, I'm looking for the reverse. There are a few comments describing the reverse, but you do not get the same points if you go back and forth between the two equations.

Given an x and y pixel coordinate how do I calculate the latitude and longitude on the map?


Solution

  • Have a look at the Javascript implementation on this page.

    You can use the Conv.m2ll() function:

    var latlon=Conv.m2ll(pixel_x, pixel_y);