i am trying to convert from/to ellipsoidal coordinates (lat,lng,alt) to/from cartesian(x,y,z) i wrote the below code to do the conversion, but given the initial values of the gpsLat and gpsLng i receive certain value ofr the northing and Easting, but the problem is when I convert from Northing and Easting to get the Longitude i do not get the same longitude which is 8.427421853866282

the equation i am using i found it in


please let me know how to get the correct values


public static void main(String[] args) {
    double semiMajorAxis = 149598023; //in km
    double eccentricity = 0.0167086;
    double radOfCurvature;
    double Northing;
    double Easting;
    double computedLng;

    double gpsLat = 49.01511835412477;
    double gpsLng = 8.427421853866282;
    double gpsAlt = 137.56704112819037;

    radOfCurvature = semiMajorAxis/Math.sqrt(1 - ( (Math.pow(eccentricity,2) * Math.pow(Math.sin(gpsLat), 2)) ) );
    Northing = (radOfCurvature + gpsAlt) * Math.cos(gpsLat) * Math.sin(gpsLng);
    Easting = (radOfCurvature + gpsAlt) * Math.cos(gpsLat) * Math.cos(gpsLng);
    computedLng = Math.atan(Northing/Easting);

    System.out.println("Northing: " + Northing);
    System.out.println("Easting: " + Easting);
    System.out.println("computedLng: " + computedLng);

result of the code

Northing: 3.9587600919687316E7
Easting: -2.5566975079396147E7
computedLng: -0.9973561069030983

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.