MKDistanceFormatter
The MKDistanceFormatter class implements a formatter object for geographic distances. You can apply a distance formatter in places where you need to specify distances and know that the values are formatted appropriately for the user’s locale and language. You can also parse existing format strings to retrieve the corresponding distance value.
-
Creates a string based on the specified distance.
Declaration
Swift
func stringFromDistance(_distance: CLLocationDistance) -> StringObjective-C
- (NSString *)stringFromDistance:(CLLocationDistance)distanceParameters
distanceThe distance value.
Return Value
A user-readable string that specifies the distance value.
Availability
Available in iOS 7.0 and later.
-
Returns the distance value contained in a formatted string.
Declaration
Swift
func distanceFromString(_distance: String) -> CLLocationDistanceObjective-C
- (CLLocationDistance)distanceFromString:(NSString *)distanceParameters
distanceA formatted string that specifies a distance.
Return Value
The distance value represented by the string.
Availability
Available in iOS 7.0 and later.
-
The locale to use when formatting strings.
Declaration
Swift
@NSCopying var locale: NSLocale!Objective-C
@property(copy, nonatomic) NSLocale *localeDiscussion
If you do not specify an explicit locale, the formatter uses the user’s current locale information.
Availability
Available in iOS 7.0 and later.
-
The measuring system (imperial or metric) to use for units.
Declaration
Swift
var units: MKDistanceFormatterUnitsObjective-C
@property(assign, nonatomic) MKDistanceFormatterUnits unitsDiscussion
You can use this property to explicitly set the measuring system for units. The default value of this property is
MKDistanceFormatterUnitsDefault, which bases the measuring system on the user’s locale.Availability
Available in iOS 7.0 and later.
-
The preferred style for units.
Declaration
Swift
var unitStyle: MKDistanceFormatterUnitStyleObjective-C
@property(assign, nonatomic) MKDistanceFormatterUnitStyle unitStyleDiscussion
Units can be abbreviated or fully spelled out. The default value of this property is
MKDistanceFormatterUnitStyleDefault, which bases the style on the user’s locale and language settings.Availability
Available in iOS 7.0 and later.
-
Constants that reflect the type of units to use in the string.
Declaration
Swift
enum MKDistanceFormatterUnits : UInt { case Default case Metric case Imperial case ImperialWithYards }Objective-C
typedef { MKDistanceFormatterUnitsDefault, MKDistanceFormatterUnitsMetric, MKDistanceFormatterUnitsImperial, MKDistanceFormatterUnitsImperialWithYards } MKDistanceFormatterUnits;Constants
-
DefaultMKDistanceFormatterUnitsDefaultThe format uses the locale information to determine which units to use. Some locales mix metric and imperial units so do not assume this means one or the other.
Available in iOS 7.0 and later.
-
MetricMKDistanceFormatterUnitsMetricThe format uses metric units.
Available in iOS 7.0 and later.
-
ImperialMKDistanceFormatterUnitsImperialThe format uses imperial units.
Available in iOS 7.0 and later.
-
ImperialWithYardsMKDistanceFormatterUnitsImperialWithYardsThe format uses imperial units that include measurements in yards.
Available in iOS 7.0 and later.
Import Statement
Objective-C
@import MapKit;Swift
import MapKitAvailability
Available in iOS 7.0 and later.
-
-
Constants that indicate the format style to use for strings.
Declaration
Swift
enum MKDistanceFormatterUnitStyle : UInt { case Default case Abbreviated case Full }Objective-C
typedef { MKDistanceFormatterUnitStyleDefault = 0, MKDistanceFormatterUnitStyleAbbreviated, MKDistanceFormatterUnitStyleFull } MKDistanceFormatterUnitStyle;Constants
-
DefaultMKDistanceFormatterUnitStyleDefaultThe decision to abbreviate is based on the current locale and user language settings.
Available in iOS 7.0 and later.
-
AbbreviatedMKDistanceFormatterUnitStyleAbbreviatedUse abbreviated units. For example, use the abbreviation
kminstead ofkilometer.Available in iOS 7.0 and later.
-
FullMKDistanceFormatterUnitStyleFullSpell out units in full. For example, use
kilometerinstead of the abbreviationkm.Available in iOS 7.0 and later.
Import Statement
Objective-C
@import MapKit;Swift
import MapKitAvailability
Available in iOS 7.0 and later.
-
Copyright © 2016 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-03-21
