-
-
Save gcapnias/b613cbdd0c105b6173fa to your computer and use it in GitHub Desktop.
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 radius = 6378137.0; | |
| var x = radius * lon * Math.PI / 180.0; | |
| var y = radius * Math.log(Math.tan(Math.PI / 4.0 + lat * Math.PI / 360.0)); | |
| return [x, y] | |
| } | |
| lon= -77.035974 | |
| lat = 38.898717 | |
| console.log(degrees2meters(lon,lat)) | |
| // should result in: [-8575605.398443861, 4707174.018280405] |
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 meters2degress = function(x,y) { | |
| var radius = 6378137.0; | |
| var lon = (180 / Math.PI) * (x / radius); | |
| var lat = (360 / Math.PI) * (Math.atan(Math.exp(y / radius)) - (Math.PI / 4)); | |
| return [lon, lat] | |
| } | |
| x = -8575605.398443861; | |
| y = 4707174.018280405; | |
| console.log(meters2degress(x,y)) | |
| // should result in: [-77.03597399999998, 38.89871699999999] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See it in action: http://jsfiddle.net/gcapnias/a7rv839j/