1

In Java it is possible to format date-time information by means of formatter classes and methods.

Just a format string has to be passed as parameter.

Many format strings are possible.

Examples here

https://developer.android.com/reference/java/text/SimpleDateFormat#examples

Letters are used to refer to digits and information.

I am interested in formatting latitude/longitude information. It seems that the main formats are:

(latitude or longitude)

[+-]DDD.DDDDD

[+-]DDD:MM.MMMMM

DDD:MM:SS.SSSSS

(I do not know whether [+-] is missing from the third format)

see https://developer.android.com/reference/android/location/Location.html#constants_2

As you can see also with lat/long formatting, letters are used.

I would like to know if it is possible to use a format string like in the date-time case.

(by means of existing methods or creating them anew)

So a formatter accepts latitude,longitude and the format string, and return a formatted string. A very general method could handle also other coordinate formats.

P5music
  • 3,197
  • 2
  • 32
  • 81
  • FYI, the terribly flawed date-time classes such as `java.util.Date`, `java.util.Calendar`, & `java.text.SimpleDateFormat` are now legacy, supplanted by [*java.time*](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html) classes. Most *java.time* functionality is back-ported to Java 6 & Java 7 in the [***ThreeTen-Backport***](http://www.threeten.org/threetenbp/) project. Further adapted for earlier Android (<26) in [***ThreeTenABP***](https://github.com/JakeWharton/ThreeTenABP). See [*How to use ThreeTenABP…*](http://stackoverflow.com/q/38922754/642706). – Basil Bourque Jan 13 '20 at 22:13
  • Duplicate?: [*How to format GPS latitude and longitude?*](https://stackoverflow.com/q/21382230/642706) – Basil Bourque Jan 13 '20 at 22:16

0 Answers0