3

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?

  • The gist is using feet, plus yeah, I haven't seen those values. John Snyder gives y = R*ln(tan(PI/4.0 + phi/2)) with phi in radians. – mkennedy Aug 31 '16 at 19:11
  • @mkennedy Where do you get that the gist is using feet? The function is called degrees2meters, and the magic number 20037508.34 is half the Earth's circumference at the equator in meters. – Kevin Krumwiede Sep 1 '16 at 22:27
  • Oops, my mistake. Radius of wgs84/grs80 is 20.9 million feet. I saw the 20 million and jumped to the wrong conclusion. – mkennedy Sep 1 '16 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.