Last active
November 2, 2024 07:36
-
-
Save mudpuddle/6115083 to your computer and use it in GitHub Desktop.
Convert Web Mercator to WGS 84 Lat/Long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MercatorToLatLon(mercX, mercY) { | |
var rMajor = 6378137; //Equatorial Radius, WGS84 | |
var shift = Math.PI * rMajor; | |
var lon = mercX / shift * 180.0; | |
var lat = mercY / shift * 180.0; | |
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0); | |
return { 'Lon': lon, 'Lat': lat }; | |
} | |
//example use | |
var LatLon = MercatorToLatLon(-10072092.937600996, 5100841.6350086592); | |
alert('Result: Lat = ' + LatLon.Lat + ', Lon = ' + LatLon.Lon); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment