I am a really beginner into web-cartography, so sorry if this subject is rudimentary or basic but I truly search for a long time and I am still stick in it.

So the problem is:

I don't understand why this code don't convert correctly my coordinates (exprimed in google mercator epsg:900913) to WGS84 web mercator epsg:4326:

   Proj4js.defs["EPSG:4326"] = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
Proj4js.defs["EPSG:900913"]= "+title=GoogleMercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";

var dest = new Proj4js.Proj("EPSG:4326");    
var source = new Proj4js.Proj("EPSG:900913");
var point = new Proj4js.Point( 85286.417057415703, 4347668.9422677439 ); 
Proj4js.transform(source, dest, point);
var transformation = Proj4js.transform(source, dest, point);
alert(point.y + "," + point.x);

I should have in return x (long) = 0.7661409 and y(lat) =36.3411771 (calculated by http://twcc.free.fr/) but with this code I have: x=0.0003264583485814848 y=0.000006882360979601046

  • I'm not sure how you're doing it, but you're converting twice. If I take the original values, unproject them, I get the twcc results. If I treat those results as EPSG:3857 and unproject them again, I get your results.
    – mkennedy
    Commented Dec 12, 2014 at 18:26

2 Answers 2


Google Mercator is now EPSG:3857, while 900913 has been dropped from the list of EPSG codes.

Furthermore, there is some kind of hack inside the projection definition, because Google mercator is calculated on a sphere (a=b), but the lat/lon coordinates are that of the WGS84 ellisoid. This is only implemented correctly for EPSG:3857.

  • I try with these codes: Proj4js.defs["SR-ORG:6864"] = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["SR-ORG:7483"] = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"; wich are both epsg:3857, but I still have the same kind of results :(
    – Qassim
    Commented Oct 4, 2014 at 8:16

Different infos:

  • some lines are not useful

By default, these below projections already exist so you do not need to declare them

Proj4js.defs["EPSG:4326"] = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
Proj4js.defs["EPSG:900913"]= "+title=GoogleMercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";

You also have to remove or the transformation happens twice as pointed by other answer.

Proj4js.transform(source, dest, point);

So the minimum to get the result with you current code is:

var src = new Proj4js.Proj("EPSG:900913");
var point = new Proj4js.Point(85286.417057415703, 4347668.9422677439); 
//Do your conversion 
Proj4js.transform(src, Proj4js.WGS84, point) 
//The point object no has the converted coordinates 
console.log(point.x + "," + point.y);

For the last line, don't use alert: it's an outdated practice when there was no browser debugger. You should see a bit browser debugging at http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820

  • You can maybe use the updated version of the library (the 2.x series) from http://proj4js.org (where you will also find the example I will use below)

With the proj4js v2.x, your projection conversion is possible with just below lines:

var coordinatesEPSG4326 = proj4('EPSG:3857').inverse([85286.417057415703, 4347668.9422677439]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.