commit de2ce6e35c8faaaaf9fb6fa3d2ea99804c7dad9d
parent 820becc820dd4ff38b631db877817cab661c7ca8
Author: Michael Camilleri <[email protected]>
Date: Sat, 17 Oct 2026 06:40:56 +0900
Use device for place coordinates
A place answer's coordinate meant different things depending on where
the answer came from. New answers recorded the report's location fix,
but imported answers recorded the saved place's own fixed location, and
a place chosen from Apple Maps stored the directory's coordinate as its
own.
This commit takes both from the device. The importer now gives each
place answer the coordinate and accuracy of its report's own location,
as new answers have, and a report without a location gives its answer
none. Reporter's place location still becomes the place's coordinate,
and stays in the legacy snapshot. Reports already imported keep their
old answer coordinates, as a re-import leaves them alone.
A place chosen from Apple Maps now takes the report's location as its
coordinate when the report is within the place's region. A place chosen
from further away, such as a search result in another city, gets no
coordinate rather than a misleading one, and comes back through Apple
Maps by its ID.
The quick log button is also announced as 'Instant Report', matching
the label on the reports it makes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat
| M | Notes/Design.md | | | 16 | ++++++++++------ |
| M | Reportage/Services/ReporterImport/ReporterImportPlan.swift | | | 20 | ++++++++++++++------ |
| M | Reportage/Services/ReporterImport/ReporterImportVerifier.swift | | | 11 | +++++++---- |
| M | Reportage/Views/Home/HomeView.swift | | | 2 | +- |
| M | Reportage/Views/Survey/PlacePicker.swift | | | 11 | +++++++++-- |
| M | Tests/Unit/PlacePickerTests.swift | | | 17 | ++++++++++++++++- |
| M | Tests/Unit/ReporterImportPlanTests.swift | | | 21 | ++++++++++++++++++--- |
7 files changed, 75 insertions(+), 23 deletions(-)
diff --git a/Notes/Design.md b/Notes/Design.md
@@ -287,9 +287,11 @@ In the survey (`PlacePicker`): address lookup, and the nearby search starts then. The list is ranked once, for that fix, so it doesn't reshuffle while the user is choosing. - **New tokens.** Choosing a MapKit place makes a token holding its name (with - the app's language), coordinate and MapKit ID. Adding a typed name makes one - at the report's location. Either is saved only if it's still the answer when - the survey closes. + the app's language) and MapKit ID. Its coordinate is the report's own + location, when the report is within the place's region; a place chosen from + further away gets none, and comes back through MapKit by its ID. Adding a + typed name makes one at the report's location. Either is saved only if it's + still the answer when the survey closes. - **Regions.** A place is its name and a location: it covers 500 m around its coordinate, the same as the near distance. Typing a place's name inside that region chooses the place; typing it further away adds a new place with the @@ -740,6 +742,9 @@ Source: Reporter's JSON export, which has two top-level arrays, `questions` and the switch. Reports already in the store are left alone. Questions and tokens already in the store keep any edits made in Reportage, so a renamed token stays renamed; questions only gain new choice options. +- **Place answers record the report's location** as where they were given, + as new answers do. Reporter stored the place's own location with each + answer; that becomes the place token's coordinate, and stays in `legacy`. - **`legacy` is byte-exact.** The importer slices each snapshot's bytes out of the export instead of re-serialising the decoded value, which would reorder keys and reformat numbers. @@ -797,9 +802,8 @@ default); when included, each is the original JSON text as a string. other languages after answering, through the Apple Maps Server API (which takes a language parameter, but needs a key), or accept one name per place. It needs confirming that the Server API uses the same place IDs as MapKit. -- **MapKit terms.** Check that Apple's terms allow storing place names and - coordinates permanently. Also recheck on iOS that lookup by ID ignores the - app language (seen on macOS). +- **Lookup language.** Recheck on iOS that lookup by ID ignores the app + language (seen on macOS). - **Multi-select choice questions.** Reporter stores choice answers as arrays, but every answer in the archive has a single value. The survey takes one answer for now.
diff --git a/Reportage/Services/ReporterImport/ReporterImportPlan.swift b/Reportage/Services/ReporterImport/ReporterImportPlan.swift
@@ -246,7 +246,9 @@ private struct Builder {
responses.append(
Response(
questionID: question.id, prompt: reporterResponse.questionPrompt,
- value: preferred.map { value(of: $0, questionID: question.id, date: date) })
+ value: preferred.map {
+ value(of: $0, questionID: question.id, date: date, reportLocation: fields.location)
+ })
)
questionIDs.insert(question.id)
}
@@ -370,9 +372,13 @@ private struct Builder {
return answers
}
- /// Converts an answer, registering the tokens it uses.
- private mutating func value(of answer: Answer, questionID: String, date: Date) -> ResponseValue
- {
+ /// Converts an answer, registering the tokens it uses. A place answer
+ /// records where it was given, from the report's location, as new
+ /// answers do: Reporter stored the place's own location with each
+ /// answer, which goes to the place's token instead.
+ private mutating func value(
+ of answer: Answer, questionID: String, date: Date, reportLocation: ReporterLocation?
+ ) -> ResponseValue {
switch answer {
case .options(let options):
return .options(options)
@@ -405,8 +411,10 @@ private struct Builder {
return .place(
PlaceAnswer(
tokenID: tokenID,
- coordinate: coordinate,
- accuracy: location.location?.horizontalAccuracy.flatMap(Self.nonNegative)
+ coordinate: reportLocation.map {
+ Coordinate(latitude: $0.latitude.value, longitude: $0.longitude.value)
+ },
+ accuracy: reportLocation?.horizontalAccuracy.flatMap(Self.nonNegative)
))
}
}
diff --git a/Reportage/Services/ReporterImport/ReporterImportVerifier.swift b/Reportage/Services/ReporterImport/ReporterImportVerifier.swift
@@ -63,7 +63,9 @@
if response.prompt != reporterResponse.questionPrompt {
mismatch("response \(index) prompt differs")
}
- if !matches(response.value, reporterResponse, tokens: tokens) {
+ if !matches(
+ response.value, reporterResponse, tokens: tokens, reportLocation: fields.location)
+ {
mismatch("response \(index) value differs")
}
}
@@ -74,7 +76,8 @@
/// Token texts are compared too, so this is only meaningful straight
/// after an import, before any token has been renamed.
private static func matches(
- _ value: ResponseValue?, _ response: ReporterResponse, tokens: [String: Token]
+ _ value: ResponseValue?, _ response: ReporterResponse, tokens: [String: Token],
+ reportLocation: ReporterLocation?
) -> Bool {
switch value {
case nil:
@@ -101,8 +104,8 @@
&& token.text == location.text
&& (location.foursquareVenueId.map { $0 == token.place?.externalID?.value }
?? true)
- && answer.coordinate?.latitude == location.location?.latitude.value
- && answer.coordinate?.longitude == location.location?.longitude.value
+ && answer.coordinate?.latitude == reportLocation?.latitude.value
+ && answer.coordinate?.longitude == reportLocation?.longitude.value
}
}
}
diff --git a/Reportage/Views/Home/HomeView.swift b/Reportage/Views/Home/HomeView.swift
@@ -202,7 +202,7 @@ struct QuickLogButton: View {
.contentShape(.circle)
}
.buttonStyle(.plain)
- .accessibilityLabel(Text("Quick Log"))
+ .accessibilityLabel(Text("Instant Report"))
.accessibilityHint(Text("Logs this moment without a survey"))
.sensoryFeedback(.success, trigger: taps)
}
diff --git a/Reportage/Views/Survey/PlacePicker.swift b/Reportage/Views/Survey/PlacePicker.swift
@@ -192,7 +192,11 @@ final class PlacePicker {
return [token]
}
- /// Gives a directory place a token, the first time it's chosen.
+ /// Gives a directory place a token, the first time it's chosen. Its
+ /// coordinate is the report's own location, if the report is within the
+ /// place's region: that comes from the device rather than the directory.
+ /// A place chosen from further away has none, and is found again through
+ /// the directory by its ID.
private func adopt(_ candidate: PlaceCandidate) {
let mapKitID = Self.mapKitID(of: candidate)
guard directoryTokenIDs[mapKitID] == nil,
@@ -200,12 +204,15 @@ final class PlacePicker {
else { return }
let id = UUID().uuidString
directoryTokenIDs[mapKitID] = id
+ let coordinate = location.map(\.coordinate).flatMap { here in
+ place.coordinate.distance(to: here) <= PlaceRanking.regionRadius ? here : nil
+ }
newTokens[id] = Token(
id: id,
questionID: questionID,
text: place.name,
place: PlaceDetails(
- coordinate: place.coordinate,
+ coordinate: coordinate,
names: place.language.map { [LocalisedName(language: $0, text: place.name)] } ?? [],
externalID: ExternalPlaceID(source: .mapKit, value: place.id)
),
diff --git a/Tests/Unit/PlacePickerTests.swift b/Tests/Unit/PlacePickerTests.swift
@@ -146,10 +146,11 @@ struct PlacePickerTests {
#expect(token.questionID == "Q")
#expect(token.text == "Kiosk")
#expect(token.modifiedAt == Date(timeIntervalSince1970: 9))
+ // The coordinate is the report's location, not the directory's.
#expect(
token.place
== PlaceDetails(
- coordinate: place.coordinate,
+ coordinate: Self.here,
names: [LocalisedName(language: "en", text: "Kiosk")],
externalID: ExternalPlaceID(source: .mapKit, value: "M1")))
@@ -164,6 +165,20 @@ struct PlacePickerTests {
#expect(picker.selection == nil)
}
+ @Test("A directory place chosen from far away gets no coordinate")
+ func adoptDistantPlace() async throws {
+ let far = Self.directoryPlace("M9", "Faraway Café", at: Self.north(3_000))
+ let picker = makePicker(directory: FakeDirectory(results: ["far": [far]]))
+ picker.setLocation(LocationContext(coordinate: Self.here))
+ picker.query = "far"
+ await picker.settle()
+
+ picker.toggle(try #require(picker.candidate(id: "mapKit:M9")))
+ let token = try #require(picker.usedNewTokens(now: Date()).first)
+ #expect(token.place?.coordinate == nil)
+ #expect(token.place?.externalID == ExternalPlaceID(source: .mapKit, value: "M9"))
+ }
+
@Test("A new place is added where the report is")
func addNewPlace() async throws {
let picker = makePicker()
diff --git a/Tests/Unit/ReporterImportPlanTests.swift b/Tests/Unit/ReporterImportPlanTests.swift
@@ -210,10 +210,12 @@ struct ReporterImportPlanTests {
#expect(
first.responses[2].value
== .place(
+ // Where the answer was given is the report's location,
+ // not the place's.
PlaceAnswer(
tokenID: Self.tokenID(3),
- coordinate: Coordinate(latitude: 35.6582, longitude: 139.7016),
- accuracy: 30
+ coordinate: Coordinate(latitude: 35.6581, longitude: 139.7017),
+ accuracy: 65
))
)
#expect(try report(2).responses[0].value == .text("Long day."))
@@ -271,13 +273,26 @@ struct ReporterImportPlanTests {
Issue.record("Expected a place")
return
}
- #expect(answer.accuracy == nil)
+ // The place's own accuracy is invalid; the report's fix isn't.
+ #expect(answer.accuracy == 10)
let office = try token(answer.tokenID)
#expect(office.text == "Office")
#expect(office.place?.externalID == nil)
#expect(office.place?.coordinate == Coordinate(latitude: 35.66, longitude: 139.7))
}
+ @Test("A place answer in a report without a location records no coordinate")
+ func placeWithoutReportLocation() throws {
+ let json = #"""
+ {"questions":[{"uniqueIdentifier":"q","prompt":"Where?","questionType":3}],"snapshots":[
+ {"uniqueIdentifier":"00000000-0000-4000-8000-000000000001","date":"2016-01-01T12:00:00+0900","reportImpetus":2,"responses":[{"questionPrompt":"Where?","locationResponse":{"text":"Home","uniqueIdentifier":"H","location":{"latitude":35.1,"longitude":139.1,"horizontalAccuracy":5}}}]}]}
+ """#
+ let plan = ReporterImportPlan(archive: try ReporterArchive(data: Data(json.utf8)))
+ #expect(plan.reports.first?.responses.first?.value == .place(PlaceAnswer(tokenID: "H")))
+ #expect(
+ plan.tokens.first?.place?.coordinate == Coordinate(latitude: 35.1, longitude: 139.1))
+ }
+
@Test("A token's latest text wins, and the conflict is reported")
func conflictingTokenTexts() throws {
let json = #"""