您的位置:首页 > 移动开发 > Android开发

android GPS度分秒与double之间的相互转化

2015-07-02 15:29 573 查看
/**
* double转化成度分秒   105.9876543 -> 105/1,59/1,15555/1000
* @param coord
* @return
*/
public static String dec2DMS(double coord) {
coord = coord > 0 ? coord : -coord; // -105.9876543 -> 105.9876543
String sOut = Integer.toString((int) coord) + "/1,"; // 105/1,
coord = (coord % 1) * 60; // .987654321 * 60 = 59.259258
sOut = sOut + Integer.toString((int) coord) + "/1,"; // 105/1,59/1,
coord = (coord % 1) * 60000; // .259258 * 60000 = 15555
sOut = sOut + Integer.toString((int) coord) + "/1000"; // 105/1,59/1,15555/1000
return sOut;
}

/**
* 度分秒转换成double   105/1,59/1,15555/1000 -> 105.9876543  
* @param sDMS
* @return
*/
public static double dms2Dbl(String sDMS) {
double dRV = 999.0;
try {
String[] DMSs = sDMS.split(",", 3);
String s[] = DMSs[0].split("/", 2);
dRV = (new Double(s[0]) / new Double(s[1]));
s = DMSs[1].split("/", 2);
dRV += ((new Double(s[0]) / new Double(s[1])) / 60);
s = DMSs[2].split("/", 2);
dRV += ((new Double(s[0]) / new Double(s[1])) / 3600);
} catch (Exception e) {
}
return dRV;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: