GeoURI

0.1.1

A Swift implementation of the geo URI scheme.
designedbyclowns/GeoURI

What's New

0.1.1

2024-04-13T18:06:01Z

Update readme

Latest Release Swift Package Manager License

GeoURI

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.

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

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)
}

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 let parsingError as? GeoURIParsingError {
        print("A parsing error occurred: \(parsingError.errorDescription)")
    } catch {
        print("\(error)")
    }
}

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-documentation

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

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue May 21 2024 14:08:50 GMT-0900 (Hawaii-Aleutian Daylight Time)