GeoURI

1.0.0

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

What's New

1.0.0

2024-09-25T16:23:52Z

What's Changed

This release adds support for swift 6.0.

As part of that the GeoURI type has been changed from a class to a struct.

It also removes the legacy Formatter sub class in favor of the modern FormatStyle approach.

Other changes include adding conformance to Sendable where possible and adopting the new swift testing framework.

Full Changelog: 0.1.1...1.0.0

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 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-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 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri May 16 2025 03:16:32 GMT-0900 (Hawaii-Aleutian Daylight Time)