Created
October 6, 2016 00:16
-
-
Save McCulloughRT/a6291ffbe009c60b0b1b7a80095ad21e to your computer and use it in GitHub Desktop.
Convert angular degrees to web mercator coordinates
This file contains hidden or 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
var degrees2meters = function(lon,lat) { | |
var x = lon * 20037508.34 / 180; | |
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); | |
y = y * 20037508.34 / 180; | |
return [x, y] | |
} | |
x = -122.6765 | |
y = 45.5231 | |
console.log(degrees2meters(x,y)) | |
// should result in: [ -13656285.510400057, 5704252.26215099 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment