Skip to content

fix: use country-level resolution for low-precision geohashes#1044

Open
malkovitc wants to merge 5 commits intopermissionlesstech:mainfrom
malkovitc:fix/887-geohash-reverse-decode-v2
Open

fix: use country-level resolution for low-precision geohashes#1044
malkovitc wants to merge 5 commits intopermissionlesstech:mainfrom
malkovitc:fix/887-geohash-reverse-decode-v2

Conversation

@malkovitc
Copy link
Copy Markdown
Contributor

Summary

Fixes #887 — When bookmarking a 2-character geohash channel (e.g., "gc" for United Kingdom), the resolved location name showed "England" instead of "United Kingdom".

Root cause: resolveCompositeAdminName() and nameForGeohashLength() in LocationStateManager.swift prioritized administrativeArea (province/state) over country for low-precision geohashes (≤2 characters). A 2-char geohash covers a region/country, so the country name should take precedence.

Changes

  • resolveCompositeAdminName() — swapped if/else priority: check pm.country first, fall back to pm.administrativeArea
  • nameForGeohashLength() — changed case 0...2 from pm.administrativeArea ?? pm.country to pm.country ?? pm.administrativeArea

How it works now

Geohash Before After
gc (UK) "England" or "England and Scotland" "United Kingdom"
u3 (France) Administrative area name "France"

Higher-precision geohashes (3+ chars) are unaffected — they continue to resolve to province/city/neighborhood as appropriate.

Test plan

  • Bookmark a 2-char geohash channel → verify country name is displayed
  • Bookmark a 3+ char geohash channel → verify province/city name still works
  • Remove and re-bookmark to clear cached names

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dedcd5ed68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +463 to +466
if let country = pm.country, !country.isEmpty, !seenAdmins.contains(country) {
seenAdmins.insert(country)
uniqueAdmins.append(country)
} else if let admin = pm.administrativeArea, !admin.isEmpty, !seenAdmins.contains(admin) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid adding admin after a seen country

In resolveCompositeAdminName, the new else if still falls back to administrativeArea when pm.country exists but was already seen, so multi-point sampling inside the same country can produce mixed labels like "United Kingdom and Scotland" instead of staying country-level. Because finalName uses only the first two collected values, this can also crowd out a true second country in border-spanning cells. For low-precision geohashes, admin fallback should only run when country is missing, not when it is duplicate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed in 6d64a6d — admin fallback now only triggers when pm.country is nil/empty, not when it's a duplicate. This prevents mixed labels like "United Kingdom and Scotland".

malkovitc and others added 2 commits February 25, 2026 11:11
Prevents mixed labels like "United Kingdom and Scotland" for
single-country geohashes. Admin fallback now only triggers when
no country is available from the placemark.
@jackjackbits
Copy link
Copy Markdown
Collaborator

I think there is still one gap here for existing users: the naming logic changes look right, but previously cached bookmark names will not be recomputed. resolveBookmarkNameIfNeeded(for:) bails out whenever bookmarkNames[gh] already exists, and bookmark names are only resolved when a bookmark is first added. So users who already have a 2-character geohash cached as something like England will keep the stale value after merge unless they manually remove and re-add the bookmark. For a bugfix aimed at bookmarked low-precision geohashes, that leaves current affected users unfixed.

jackjackbits and others added 2 commits March 12, 2026 09:54
…c applies

Users who bookmarked a <=2-char geohash before the country-first resolver
kept the old administrativeArea cache (e.g. "England" for `gc`) because
resolveBookmarkNameIfNeeded bails when bookmarkNames[gh] is non-nil. Add a
one-shot, versioned migration that drops cached names for <=2-char geohashes
on load; the next LocationChannelsSheet .onAppear re-resolves them via the
fixed logic. Higher-precision entries are untouched.
@malkovitc
Copy link
Copy Markdown
Contributor Author

Good point — fixed in 4865471. Added a one-shot versioned migration in loadPersistedState that drops cached names for ≤2-char geohashes; the next LocationChannelsSheet .onAppear re-resolves them via the new country-first path. Higher-precision entries are left alone. Covered by a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Geohash reverse decode differs

2 participants