Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 505
user3182266 Avatar asked Jan 27 '14 13:01

user3182266


1 Answers

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

like image 50
dinesh sharma Avatar answered Oct 10 '22 22:10

dinesh sharma