Last active
December 13, 2020 08:19
-
-
Save arashmad/65b0248121147d0bf6dd4e797a32e6de to your computer and use it in GitHub Desktop.
A conversion from Geographic (Latitude & Longitude) to Web Mercator (X & Y)
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
_latLong2Merc = (_lat, _lon) => { | |
/* | |
_lat => Latitude in decimal degree (Number) | |
_lon => Longitude in decimal degree (Number) | |
*/ | |
var r_major = 6378137.000 | |
var lon_rad = (_lon / 180.0 * Math.PI) | |
var x = r_major * lon_rad | |
var scale = x / _lon | |
var y = 180.0 / Math.PI * Math.log(Math.tan(Math.PI / 4.0 + _lat * (Math.PI / 180.0) / 2.0)) * scale | |
return ({ x, y }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results were tested by PostGIS
ST_Transform
function.