开发者

Conversion of GPS values from deg to dms format

开发者 https://www.devze.com 2023-04-02 09:17 出处:网络
Does anyone know how or have an Android function to convert a GPS value from d开发者_如何学JAVAecimal to DMS (degree-minute-second) format?Have a look at the class android.location.Location.

Does anyone know how or have an Android function to convert a GPS value from d开发者_如何学JAVAecimal to DMS (degree-minute-second) format?


Have a look at the class android.location.Location.

The static method convert(double, Location.FORMAT_SECONDS) is what you're looking for.


You could do the math manually.

Example code:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消