Java Degree Convert to degreesMinSecToDegrees(String position)

Here you can find the source of degreesMinSecToDegrees(String position)

Description

degrees Min Sec To Degrees

License

LGPL

Declaration

public static double degreesMinSecToDegrees(String position) throws StringIndexOutOfBoundsException 

Method Source Code

//package com.java2s;
/**/*from w  w w  .  j a  va  2s . c  om*/
 * Offers various useful methods related to geopositionning.
 * <p>License: This library is under the GNU Lesser General Public License</p>
 *
 * @author Praplan Christophe
 * @author Velen Stephane
 * @version 1.0 <p>Geneva, the 23.03.2006
 */

public class Main {

    public static double degreesMinSecToDegrees(String position) throws StringIndexOutOfBoundsException {
        double result;
        try {
            if (position.charAt(position.length() - 1) == 'W' || position.charAt(position.length() - 1) == 'E') {
                result = Double.parseDouble(position.substring(7, 12)) / 60;
                result = (Double.parseDouble(position.substring(4, 6)) + result) / 60;
                result += Double.parseDouble(position.substring(0, 3));
            } else {
                result = Double.parseDouble(position.substring(6, 11)) / 60;
                result = (Double.parseDouble(position.substring(3, 5)) + result) / 60;
                result += Double.parseDouble(position.substring(0, 2));
            }
            if (position.charAt(position.length() - 1) == 'W' || position.charAt(position.length() - 1) == 'S')
                return -result;
            else
                return result;
        } catch (StringIndexOutOfBoundsException e) {
            throw new StringIndexOutOfBoundsException("Bad entry format");
        }
    }
}

Related

  1. deg2dms(double deg)
  2. degrees(double d)
  3. degrees2Dist(double degrees, double radius)
  4. degreesDiff(double a1, double a2)
  5. degreeSin(double angle)
  6. degreesToDecimal(String input)
  7. degreesToMetres(double degrees)
  8. degreesToPercent(float n)
  9. degreesToRA(double val)