public class DistanceFormatter extends Object
Constructor and Description |
---|
DistanceFormatter(Context context,
String language,
String unitType,
int roundingIncrement)
Creates an instance of DistanceFormatter, which can format distances in meters
based on a language format and unit type.
|
Modifier and Type | Method and Description |
---|---|
static int |
calculateAbsoluteDistance(Location currentLocation,
MetricsRouteProgress metricProgress) |
SpannableString |
formatDistance(double distance)
Returns a formatted SpannableString with bold and size formatting.
|
boolean |
shouldUpdate(String language,
String unitType,
int roundingIncrement)
Method that can be used to check if an instance of
DistanceFormatter
needs to be updated based on the passed language / unitType. |
public DistanceFormatter(Context context, @NonNull String language, @NonNull String unitType, int roundingIncrement)
This constructor will infer device language and unit type using the device locale.
context
- from which to get localized strings fromlanguage
- for which languageunitType
- to use, or NONE_SPECIFIED to use default for locale countryroundingIncrement
- increment by which to round small distancespublic SpannableString formatDistance(double distance)
distance
- in meterspublic boolean shouldUpdate(@NonNull String language, @NonNull String unitType, int roundingIncrement)
DistanceFormatter
needs to be updated based on the passed language / unitType.language
- to check against the current formatter languageunitType
- to check against the current formatter unitTypepublic static int calculateAbsoluteDistance(Location currentLocation, MetricsRouteProgress metricProgress)
© 2019 Mapbox. All rights reserved.