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;
}
* 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;
}
相关文章推荐
- android 动画资源
- 被谷歌控制的 Android 不是好 Android?
- 在Android原生输入法LatinIME中添加自定义按键
- 【转】Android下编译jni库的二种方法(含示例)
- 【转】android4.1.2 CTS测试总结
- 【转】Android 源码下利用jni编译自己的项目(参考系统development/samples/SimpleJNI)
- 【转】Android用NDK和整套源码下编译JNI的不同
- Android开发:使用ViewDragHelper实现抽屉拉伸效果
- 详述Google针对Android平板App发布的十大开发准则
- Android 长按电源键和短按电源键的详细处理流程
- 【Android自定义控件】支持多层嵌套RadioButton的RadioGroup
- android自定义组合控件onFinishInflate和onSizeChanged的区别
- Android导入第三方静态库.a编译成动态库.so
- Android动画之图片动画
- android 实用代码
- Android动画之Interpolator和AnimationSet
- android属性动画—自己的测试代码
- android动画之一Tween动画
- Android Studio创建库项目及引用
- 基于android平台开发的计算器