I have an algorithm which produces an X/Y coordinate for a map based on Latitude and Longitude.
I would like to create an algorithm which does the exact opposite - takes an X and Y coordinate and returns the appropriate Lat/Long.
In my code, earthRadius, earthCircum and earthHalfRadius are constants which can be taken as given.
My program also has a zoom level, which has been taken into account in the code you see below:
Parameters: latitude, longitude, zoomLevel
double arc = earthCircum / ((1 << (zoomLevel)) * 256);
double sinLat = Math.sin(latitude);
double metersY = earthRadius / 2 * Math.log((1 + sinLat) / (1 - sinLat));
double y = (earthHalfCirc - metersY) / arc;
double metersX = earthRadius * longitude;
double x = (earthHalfCirc + metersX) / arc;
return: x, y
In case you are not familiar with code, the term (1 << (zoomLevel)) can be read as (2^zoomLevel).
Any ideas?
2007-01-18
06:39:45
·
3 answers
·
asked by
Liam D
1
in
Science & Mathematics
➔ Mathematics