Skip to content

Instantly share code, notes, and snippets.

@gcapnias
Forked from onderaltintas/degrees2meters.js
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save gcapnias/b613cbdd0c105b6173fa to your computer and use it in GitHub Desktop.

Select an option

Save gcapnias/b613cbdd0c105b6173fa to your computer and use it in GitHub Desktop.
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]
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]
@gcapnias
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment