iOS Developer Library

Developer

MapKit Framework Reference MKDistanceFormatter Class Reference

Options
Deployment Target:

On This Page
Language:

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.

  • The locale to use when formatting strings.

    Declaration

    Swift

    @NSCopying var locale: NSLocale!

    Objective-C

    @property(copy, nonatomic) NSLocale *locale

    Discussion

    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: MKDistanceFormatterUnits

    Objective-C

    @property(assign, nonatomic) MKDistanceFormatterUnits units

    Discussion

    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: MKDistanceFormatterUnitStyle

    Objective-C

    @property(assign, nonatomic) MKDistanceFormatterUnitStyle unitStyle

    Discussion

    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

    • Default

      MKDistanceFormatterUnitsDefault

      The 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.

    • Metric

      MKDistanceFormatterUnitsMetric

      The format uses metric units.

      Available in iOS 7.0 and later.

    • Imperial

      MKDistanceFormatterUnitsImperial

      The format uses imperial units.

      Available in iOS 7.0 and later.

    • ImperialWithYards

      MKDistanceFormatterUnitsImperialWithYards

      The format uses imperial units that include measurements in yards.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    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

    • Default

      MKDistanceFormatterUnitStyleDefault

      The decision to abbreviate is based on the current locale and user language settings.

      Available in iOS 7.0 and later.

    • Abbreviated

      MKDistanceFormatterUnitStyleAbbreviated

      Use abbreviated units. For example, use the abbreviation km instead of kilometer.

      Available in iOS 7.0 and later.

    • Full

      MKDistanceFormatterUnitStyleFull

      Spell out units in full. For example, use kilometer instead of the abbreviation km.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.