Skip to content

Instantly share code, notes, and snippets.

@amir-s
Forked from springmeyer/degress2meters.js
Created February 7, 2021 00:26
Show Gist options
  • Select an option

  • Save amir-s/7e320f513753f34a9a1a191fa77f8b04 to your computer and use it in GitHub Desktop.

Select an option

Save amir-s/7e320f513753f34a9a1a191fa77f8b04 to your computer and use it in GitHub Desktop.
convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913)
// See https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames for more details.
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= -77.035974
y = 38.898717
console.log(degrees2meters(x,y))
// should result in: -8575605.398444, 4707174.018280
@amir-s
Copy link
Author

amir-s commented Feb 7, 2021

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