The map widget I'm using gives me click locations in lat/long. I need to convert those coordinates to EPSG:3857 to query a database.
Most of the solutions I've found use the formula described in this gist: convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913) . But I'm in doubt about the constant 90
used in the y
calculation:
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
The formula described on Wikipedia seems to suggest that instead of 90
, I should use 85.051129
. I've found other references to that value in questions such as Transforming EPSG:3857 to EPSG:4326.
Which is correct, and why?
degrees2meters
, and the magic number20037508.34
is half the Earth's circumference at the equator in meters.