This package provides some Formatters that convert between coordinates and their textual representations.
Please see the documentation for more detailed usage instructions.
This is the primary formatter for converting coordinates. It utilizes additional formatters for specific formats.
LocationCoordinateFormatter provides a variety of configuration options for customizing both the string output and parsing coordinates from strings.
import LocationFormatter
let coordinate = CLLocationCoordinate2D(latitude: 48.11638, longitude: -122.77527)
let formatter = LocationCoordinateFormatter()
// Decimal Degrees (DD)
formatter.format = .decimalDegrees
formatter.string(from: coordinate) // "48.11638° N, 122.74231° W"
// Degrees Decimal Minutes (DDM)
formatter.format = .degreesDecimalMinutes
formatter.string(from: coordinate) // "48° 06.983' N, 122° 46.516' W"
// Degrees Minutes Seconds (DMS)
formatter.format = .degreesMinutesSeconds
formatter.string(from: coordinate) // "48° 6' 59" N, 122° 46' 31" W"
// Universal Trans Mercator (UTM)
formatter.format = .utm
formatter.string(from: coordinate) // "10U 516726m E 5329260m N"
import LocationFormatter
let formatter = LocationCoordinateFormatter()
// Decimal Degrees (DD)
formatter.format = .decimalDegrees
try formatter.coordinate(from: "48.11638° N, 122.74231° W") // (48.11638, -122.77527)
// Degrees Decimal Minutes (DDM)
formatter.format = .degreesDecimalMinutes
try formatter.coordinate(from: "48° 06.983' N, 122° 46.516' W") // (48.11638, -122.77527)
// Degrees Minutes Seconds (DMS)
formatter.format = .degreesMinutesSeconds
try formatter.coordinate(from: "48° 6' 59\" N, 122° 46' 31\" W") // (48.11638, -122.77527)
// Universal Trans Mercator (UTM)
formatter.format = .utm
try formatter.coordinate(from: "10U 516726m E 5329260m N") // (48.11638, -122.77527)
Extends String
with a convenience function to parse a coordinate from a string using all supported format.
import Location
"48.11638 °N, 122.74231° W".coordinate() // (48.11638, -122.77527)
"48° 06.983' N, 122° 46.516' W".coordinate() // (48.11638, -122.77527)
"48° 6' 59\" N, 122° 46' 31\" W".coordinate() // (48.11638, -122.77527)
"10U 516726m E 5329260m N".coordinate() // (48.11638, -122.77527)
- Provides support for converting between latitude/longitude and the UTM (Universal Transverse Mercator) coordinate systems.
- License: MIT
- Repo: https://github.com/wtw-software/UTMConversion
- Swift Package Manager command plugin for Swift-DocC.
- License: Apache License 2.0
- Repo: https://github.com/apple/swift-docc-plugin.git