HELP GPS convertion

edited May 2017 in How To...

Hi, how to convert in Processing an Latitude and Longitude for example: 43.324 to 43° 32' 14'' 628.034 to 006° 28' 20''

Thank you a lot

Answers

  • edited May 2017

    Your example is wrong :)
    Step to convert from decimal degree to sexagesimal degree:
    1) The integer part of decimal of degrees will remain the same.
    (i.e. 43.324 start with 43°)

    2) Multiply the decimal by 60.
    (i.e. 0.324 * 60 = 19.44)
    The integer part becomes the minutes (i.e. 19').

    3) Take the remaining decimal and multiply by 60. (i.e. 0.44 * 60 = 26.4)
    The resulting number becomes the seconds (i.e. 26.4"). Seconds can remain as a decimal.
    Solution: 43.324 --> 43° 19' 26.4"

    Now you must format the output to get 043° 19' 26.4"

  • I'm sorry cameyo, but how to write this sysntax in processing ? I'm new in Processing

    Regards, Fred

  • Answer ✓

    Your conversion is not correct above. And the value for longitude is not correct. Check this: https://www.thoughtco.com/decimal-degrees-conversion-1434592

    Here below is an example code to do the conversion.

    Kf

    String decimalDegToSexagesimalDeg(float inVal) {
    
      float[] items=new float[3];
      items[0]=(int)inVal;                  //Extracts integer component
      items[1]= (int)((inVal-items[0])*60); //Remove integer, then multiply by 60 and return integer component
      items[2]=inVal-(items[0]-items[1]*60);//From main val, subtract item0 and item1*60 to get seconds
    
      PVector p=new PVector((int)items[0],(int)items[1],items[2]);
      return "[ Deg., Min., Sec. ] = "+p.toString();
    }
    
    void setup(){
    
      float lat=43.324;
      println(decimalDegToSexagesimalDeg(lat));
    
    }
    
  • kfrajer, thank you for your help

Sign In or Register to comment.