LocationFormatter

1.1.1

Formatters for coordinates
salishseasoftware/LocationFormatter

What's New

1.1.1

2024-01-08T15:57:49Z

What's Changed

  • GeoURI formatter fix for iOS

Full Changelog: 1.1.0...1.1.1

Swift Latest Release Swift Package Manager License

LocationFormatter

This package provides some Formatters that convert between coordinates and their textual representations.

Usage

Please see the documentation for more detailed usage instructions.

LocationCoordinateFormatter

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.

Converting coordinates to 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"

Converting strings to coordinates

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)

Extensions

String+Location

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)

Dependencies

UTMConversion

Swift-DocC Plugin

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Mon Dec 09 2024 04:05:48 GMT-1000 (Hawaii-Aleutian Standard Time)