如何在java中将度数分钟转换为十进制 [英] How to convert degree minutes second into decimal in java

查看:237
本文介绍了如何在java中将度数分钟转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个基本的gps应用程序,我从这个格式2841'44.13597中获取图片元数据的纬度信息。

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 .

我需要的是将相同的信息转换为十进制,out将显示十进制格式的数据,如28.705450。

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

提前致谢

推荐答案

/** 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;
}

这篇关于如何在java中将度数分钟转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆