A Swift implementation of the geo URI scheme.
The geo URI scheme is a Uniform Resource Identifier (URI) scheme defined by the Internet Engineering Task Force's RFC 5870.
A 'geo' URI identifies a physical location in a two- or three-dimensional coordinate reference system in a compact, simple, human-readable, and protocol-independent way.
iOS 16, macOS 10.13, tvOS 16, watchOS 9
This package is available via Swift Package Manager.
To install it, simply add the repo URL to your project in the usual way, and import GeoURI
where needed.
A GeoURI
type can be crated from its constituent components (latitude, longitude, and an optional altitude), or from a URL that conforms the geo URI scheme.
There are also CoreLocation extension to initialize a GeoURI
from a CLLocation
or CLLocationCoordinate2D
.
An error will be thrown if any of the properties do not meet the specification.
See the documentation for a complete reference.
import GeoURI
let geoURI = try? GeoURI(latitude: 48.2010, longitude: 16.3695, altitude: 183)
let urlString = geoURI?.url.absoluteString // "geo:48.201,16.3695,183?crs=wgs84"
import GeoURI
if let let url = URL(string: "geo:-48.876667,-123.393333") {
let geoURI = try? GeoURI(url: url)
}
import CoreLocation
import GeoURI
let coordinate = CLLocationCoordinate2D(latitude: 48.2010, longitude: 16.3695)
let geoURI = try? GeoURI(coordinate: coordinate)
let urlString = geoURI?.url.absoluteString // "geo:48.2010,16.3695?crs=wgs84"
import GeoURI
if let url = URL(string: "geo:-48.876667,-123.393333") {
do {
let geoURI = try GeoURI(url: url)
} catch let parsingError as? GeoURIParsingError {
print("A parsing error occurred: \(parsingError.errorDescription)")
} catch {
print("\(error)")
}
}
Documentation of this package is provided via a DocC documentation catalog.
The official specification of RFC 5870 is the canonical reference for the GeoURI scheme.
To build the documentation from the command-line:
$ swift package generate-documentation
Add the --help
flag to get a list of all supported arguments and options.
You can also build the documentation directly in Xcode from the Product menu:
Product > Build Documentation
The documentation can then be viewed in the documentation viewer.
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
GeoURI is available under the Unlicense. See the LICENSE file for more info.