user3182266 user3182266 - 1 year ago 84
Android Question

How to format GPS latitude and longitude?

In android(java) when you get the current latitude and longitude using the function getlatitude() etc you get the coordinates in decimal format:

latitude: 24.3454523 longitude: 10.123450

I want to get this into degrees and decimal minutes to look something like this:

Latitude: 40°42′51″ N Longitude: 74°00′21″ W

Answer Source

to conver from decimals to degrees you can do as follow

String strLongitude = location.convert(location.getLongitude(), location.FORMAT_DEGREES);
String strLatitude = location.convert(location.getLatitude(), location.FORMAT_DEGREES);

reference is android developer site.


I have tried following thing and get the output:

strLongitude = Location.convert(location.getLongitude(), Location.FORMAT_DEGREES);
strLatitude = Location.convert(location.getLatitude(), Location.FORMAT_DEGREES);

OUTPUT : Long: 73.16584: Lat: 22.29924

strLongitude = Location.convert(location.getLongitude(), Location.FORMAT_SECONDS);
strLatitude = Location.convert(location.getLatitude(), Location.FORMAT_SECONDS);

OUTPUT : Long: 73:9:57.03876: Lat: 22:17:57.26472

strLongitude = Location.convert(location.getLongitude(), Location.FORMAT_MINUTES);
strLatitude = Location.convert(location.getLatitude(), Location.FORMAT_MINUTES);

OUTPUT : Long: 73:9.95065: Lat: 22:17.95441

Try different option as per your requirement

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download