Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert degree minutes second into decimal in java

Tags:

java

This is a basically gps application where i am getting the latitude information from the meta data of a picture in this format 28"41'44.13597 .

My need is to convert the same information into decimal and the out will show data in decimal format like 28.705450.

Please help through code or any references

Thanks in advance

like image 409
Satya Avatar asked May 06 '10 07:05

Satya


People also ask

When you convert degrees minutes and seconds to decimal degrees you need to divide seconds with?

There are 60 minutes in one degree and 3600 seconds in one degree. To convert minutes and seconds to decimal degrees, divide minutes by 60, divide seconds by 3600, and then add the results to obtain the decimal equivalent.


1 Answers

/** answer=hour+minutes/60+seconds/3600 */
public double convertHourToDecimal(String degree) { 
    if(!degree.matches("(-)?[0-6][0-9]\"[0-6][0-9]\'[0-6][0-9](.[0-9]{1,5})?")
        throw new IllegalArgumentException();
    String[] strArray=degree.split("[\"']");
    return Double.parseDouble(strArray[0])+Double.parseDouble(strArray[1])/60+Double.parseDouble(strArray[2])/3600;
}
like image 58
TiansHUo Avatar answered Sep 28 '22 03:09

TiansHUo