【发布时间】:2011-09-06 00:49:48
【问题描述】:
有谁知道如何或有 Android 功能将 GPS 值从十进制转换为 DMS(度-分-秒)格式?
【问题讨论】:
标签: android dictionary gps
有谁知道如何或有 Android 功能将 GPS 值从十进制转换为 DMS(度-分-秒)格式?
【问题讨论】:
标签: android dictionary gps
看看课程android.location.Location。
静态方法convert(double, Location.FORMAT_SECONDS) 就是您要找的。p>
【讨论】:
您可以手动计算。
示例代码:
decimal = ...; // Your given value
boolean neg = decimal < 0;
decimal = abs(decimal);
deg = floor(decimal); // Round down
minutes = floor((decimal * 60) % 60); // This is an integer in the range [0, 60)
seconds = (decimal * 3600) % 60; // This is a decimal in the range [0, 60)
if (neg) prepend minus sign;
【讨论】:
floor (-74.0125) 是 -75,但经度是 74° 0′ 45″ W)。
// Your given value, assumed to be nonnegative。