I use the pure mathematical method to convert Mercator Sphere coordinates to latitude and longitude.

I needed it in JavaScript and implemented it in the following way:

function MercatorToLatLon(mercX, mercY) {

var rMajor = 6378137; //Equatorial Radius, WGS84

var shift = Math.PI * rMajor;

var lon = mercX / shift * 180.0;

var lat = mercY / shift * 180.0;

lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) – Math.PI / 2.0);

return { ‘Lon’: lon, ‘Lat’: lat };

}

You can read it up in my blog (http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/) at greater length.

Thanks!

]]>For expediency here is a raw projection:

new Point(point.x, Math.log(Math.tan(0.25 * Math.PI + 0.5 * point.y)));

and the raw un-projection:

new Point(point.x, 2 * Math.atan(Math.pow(Math.E, point.y)) – 0.5 * Math.PI);

For more mathematical detail see: http://mathworld.wolfram.com/MercatorProjection.html

]]>