Search code examples
javascriptmappinggeospatial

Converting Cartesian (ECEF) to WGS84 (Lat/Long Decimal) using JavaScript


I have a javascript file that is reading a text file containing cartesian coordinates. I can parse out the X,Y,Z values; however I need to convert these to lat/long in decimal format. These output values will be used for google map markers.

I have been researching and there are definitely lots of guides out there regarding the conversion of lat/long to cartesian, however I need this to work the opposite direction.

Tried something along the lines of:

//convert to lat long dec
var tmp = cartZ/6371;
//convert to radians
var tmpR = tmp * Math.PI / 180;
var lat = Math.asin(tmpR);
latFinal = lat * 180 / Math.PI;
alert (latFinal);

Usually this is completely wrong... Not sure if I am even on the right track!

If anyone has done this before using javascript that would be great.


Solution

  • I ended up using the following: javascript routines

    Was exactly what I needed. Hopefully this post is helpful to others. Thanks!