Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a GeoURI formatter #3

Merged
merged 2 commits into from
Jan 8, 2024
Merged

Add a GeoURI formatter #3

merged 2 commits into from
Jan 8, 2024

Conversation

hishma
Copy link
Contributor

@hishma hishma commented Jan 7, 2024

This PR add a new formatter that converts between CLLocation types and their GeoURI representations as defined by rfc5870.

You can verify this in the Swift REPL

% swift run --repl
Building for debugging...
[2/2] Compiling plugin Swift-DocC Preview
Build complete! (0.19s)
Launching Swift REPL with arguments: repl -I/Users/jeffj/Developer/sss/LocationFormatter/.build/arm64-apple-macosx/debug -L/Users/jeffj/Developer/sss/LocationFormatter/.build/arm64-apple-macosx/debug -llocationformatter__REPL
Welcome to Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5).
Type :help for assistance.
  1> import LocationFormatter
  2> import CoreLocation
  3> let formatter = GeoURILocationFormatter()
  4> let location = formatter.location(from: "geo:48.11638,-122.77527")
  5> location.description
$R0: String = "<+48.11638000,-122.77527000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 1/7/24, 12:09:18 Pacific Standard Time"
  6> formatter.string(fromLocation: location)
$R1: String? = "geo:48.11638,-122.77527"

  7> formatter.options.insert(.includeCRS)
  8> formatter.string(fromLocation: location) 
$R3: String? = "geo:48.11638,-122.77527;crs=wgs84"
  9> :quit

@hishma hishma added the enhancement New feature or request label Jan 7, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a use case for both case sensitive and insensitive parsing? What other parsing options could there be?

Copy link
Contributor Author

@hishma hishma Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the spec says it should be case insensitive, but prefer lower case. But I was thinking it might make sense to let the user determine the behavior to fit their use case.

Future iterations could also support some unofficial extensions that other systems use (looking at you android).

@hishma hishma merged commit 909b5f7 into main Jan 8, 2024
1 check passed
@hishma hishma deleted the geoURI branch January 8, 2024 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants