designedbyclowns/GeoURI
A Swift implementation of the geo URI scheme.
Requirements
iOS 16, macOS 10.13, tvOS 16, watchOS 9
Installation
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.
Usage
A GeoURI type can be created 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.
Creating a GeoURI
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"Create a GeoURI from a URL
import GeoURI
if let let url = URL(string: "geo:-48.876667,-123.393333") {
let geoURI = try? GeoURI(url: url)
}Create a GeoURI from a String
import GeoURI
let geoURI = try GeoURI("geo:48.201,16.3695", format: GeoURI.FormatStyle)Create a String from a GeoURI
geoURI.formatted() // "geo:48.201,16.3695"
geoURI.formatted(.full) // "geo:48.201,16.3695;crs=wgs84"CoreLocation
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"Handling errors
import GeoURI
if let url = URL(string: "geo:-48.876667,-123.393333") {
do {
let geoURI = try GeoURI(url: url)
} catch GeoURIParsingError {
print("A parsing error occurred: \(parsingError.errorDescription)")
}
}Documentation
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.
Building the documentation
To build the documentation from the command-line:
$ swift package generate-documentationAdd the --help flag to get a list of all supported arguments and options.
Xcode
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.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
License
GeoURI is available under the Unlicense. See the LICENSE file for more info.
Package Metadata
Repository: designedbyclowns/GeoURI
Stars: 9
Forks: 1
Open issues: 3
Default branch: main
Primary language: swift
License: Unlicense
README: README.md