Last active
December 20, 2015 10:20
-
-
Save mudpuddle/6115088 to your computer and use it in GitHub Desktop.
Convert WGS 84 Lat/Long to Web Mercator
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 LatLonToMercator(lat, lon) { | |
var rMajor = 6378137; //Equatorial Radius, WGS84 | |
var shift = Math.PI * rMajor; | |
var x = lon * shift / 180; | |
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); | |
y = y * shift / 180; | |
return {'X': x, 'Y': y}; | |
} | |
//example use | |
var XY = LatLonToMercator(38.878586, -76.989626); | |
alert('Mercator X:' + XY.X + ', Mercator Y:' + XY.Y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment