Keith
Keith

Reputation: 261

Conversion of GPS values from deg to dms format

Does anyone know how or have an Android function to convert a GPS value from decimal to DMS (degree-minute-second) format?

Upvotes: 2

Views: 2485

Answers (2)

JoeSch
JoeSch

Reputation: 81

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

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

Upvotes: 3

Nayuki
Nayuki

Reputation: 18542

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;

Upvotes: 2

Related Questions