I have the Lat/Long value of New York City, NY; 40.7560540,-73.9869510 and a flat image of the earth, 1000px × 446px.
I would like to be able to convert, using Javascript, the Lat/Long to an X,Y coordinate where the point would reflect the location.
So the X,Y coordinate form the Top-Left corner of the image would be; 289, 111
Things to note:
- don't worry about issues of what projection to use, make your own assumption or go with what you know might work
- X,Y can be form any corner of the image
- Bonus points for the same solution in PHP (but I really need the JS)
I've written a function which works for Mercator maps. Especially if your image doesn't cover the whole world, means it also works with cropped maps: https://stackoverflow.com/a/10401734/730823
The projection you use is going to change everything, but this will work assuming a Mercator projection:
There's a good Javascript library, PROJ4JS, that allows you to do transformations between different projections.
If you have a picture of the whole earth, the projection does always matter. But maybe I just don't understand your question.
A basic conversion function in js would be:
This will return the number of pixels from upper left. This function assumes the following: