Skip to content

Formatting units

Jiří M. aka Menion edited this page Oct 7, 2016 · 1 revision

Get format

Locus API allows to format units for users, based on it's settings in Locus application itself. For this you need LocusInfo object. How to get it read here.

LocusInfo contains all necessary parameters for formatting units, available under getUnitsFormatX() functions. Currently supported are units for altitude, angle, area, energy, length, slope, speed, temperature and weight.

Received values are constants defined in UtilsFormat class.

Formatting values

We know user's defined parameters and we have our new favorite UtilsFormat class, so let's start.

Every unit has three main functions. Let's show it on Altitude value as a sample.

  • formatAltitude(int format, double altitude, boolean addUnits) is main formatting function for formatting altitude values. Format parameter is value received from LocusInfo object, altitude is value in metres we wants to format and last flag just define if we wants to attach units to final number.
  • formatAltitudeValue(int format, double altitude) then serve for formatting of value itself. More precisely it convert metres to any other units.
  • formatAltitudeUnits has simple purpose of getting an units for certain format

All other units has similarly named functions, that may be used for formatting values in same format as user defined in core application itself.