Skip to content

Commit

Permalink
Add geoURL format to string coordinate extension
Browse files Browse the repository at this point in the history
  • Loading branch information
hishma committed Jun 24, 2024
1 parent e0b2fee commit 97fcb79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/LocationFormatter/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public extension String {
LocationCoordinateFormatter(format: .decimalDegrees),
LocationCoordinateFormatter(format: .degreesDecimalMinutes),
LocationCoordinateFormatter(format: .degreesMinutesSeconds),
LocationCoordinateFormatter(format: .utm)
LocationCoordinateFormatter(format: .utm),
LocationCoordinateFormatter(format: .geoURI),
]

for formatter in formatters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ struct LocationCoordinateFormatterTests {
#expect(formatter.string(from: CLLocationCoordinate2D.nullIsland) == "31N 166021m E 000000m N")
}

@Test func geoURI() {
let formatter = LocationCoordinateFormatter(format: .geoURI)

#expect(formatter.string(from: CLLocationCoordinate2D.portTownsend) == "geo:48.11638,-122.77527")
#expect(formatter.string(from: CLLocationCoordinate2D.capeHorn) == "geo:-55.97917,-67.275")
#expect(formatter.string(from: CLLocationCoordinate2D.seychelles) == "geo:-4.67785,55.46718")
#expect(formatter.string(from: CLLocationCoordinate2D.capeHorn) == "geo:-55.97917,-67.275")
#expect(formatter.string(from: CLLocationCoordinate2D.faroeIslands) == "geo:62.06323,-6.87355")
#expect(formatter.string(from: CLLocationCoordinate2D.pointNemo) == "geo:-48.876667,-123.393333")

}

@Suite struct SymbolStyle {

@Test func none() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ struct UTMCoordinateFormatterTests {
#expect(coordinate.latitude.isApproximatelyEqual(to: 48.116380622937946, absoluteTolerance: 0.00001))
#expect(coordinate.longitude.isApproximatelyEqual(to: -122.77527139988439, absoluteTolerance: 0.00001))
}

}
}
}
19 changes: 19 additions & 0 deletions Tests/LocationFormatterTests/StringTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing
import CoreLocation
import Numerics
@testable import LocationFormatter

struct StringTests {

@Test(arguments: [
"48.11638° N, 122.77527° W", // decimalDegrees
"48° 06.983′ N, 122° 46.516′ W", // degreesDecimalMinutes
"48° 6′ 59″ N, 122° 46′ 31″ W", // degreesMinutesSeconds
"10U 516726m E 5329260m N", // UTM
"geo:48.11638,-122.77527" // GeoURI
]) func coordinate(string: String) throws {
let coordinate = try #require(string.coordinate())
#expect(coordinate.isApproximatelyEqual(to: .portTownsend, absoluteTolerance: 0.0001))
}

}

0 comments on commit 97fcb79

Please sign in to comment.