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
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.
Edit
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With