Skip billed Google Geolocation API call when browser location is out of bounds - #1472
Merged
Merged
Conversation
…ounds Previously, if the browser's HTML5 Geolocation API successfully returned real coordinates that were just outside our supported SF bounding box, getLocation() treated that identically to a permission denial or unsupported-browser error, and fell through to call the (billed) Google Geolocation API as a fallback. Since we already have a real, precise answer at that point, calling Google's IP-based (and much less precise) Geolocation API is very unlikely to produce a meaningfully different result -- it's just an unnecessary billed request. This adds a distinct OutOfBoundsLocationError so getLocation() can tell the two cases apart, and skips straight to the default SF location when the browser's real location is simply out of bounds. All other rejection reasons (permission denied, unsupported browser, timeout, etc.) still fall back to Google as before. Resolves the @todo left in the original implementation.
lgarofalo
requested review from
dfloo,
jjfreund,
richardxia and
schroerbrian
September 3, 2026 02:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getLocation()inapp/utils/location.tstries the free HTML5 browser Geolocation API first, and only falls back to the billed Google Geolocation API on failure:However,
getLocationBrowser()rejects in two very different situations, and this code couldn't tell them apart:In case (2), we already have a real answer. Calling Google's Geolocation API (which is IP-based and much less precise than GPS) afterwards is very unlikely to produce a meaningfully different result -- it's just an unnecessary billed API call every time this happens. This was flagged as a known
@todoin the original code:Fix
Added a distinct
OutOfBoundsLocationErrorthatgetLocationBrowser()throws specifically for case (2), sogetLocation()can tell the two rejection reasons apart:All other behavior is unchanged: permission denials, unsupported browsers, and timeouts still fall back to Google's Geolocation API (with its existing 2hr cache) exactly as before.
Scope
Standalone, minimal fix targeting just this one known bug/TODO. Doesn't touch the map-loading changes from #1470, CI workflow, or any other geolocation caching behavior (e.g. cache TTL).
Testing
npx tsc --noEmit-- passesnpx eslint app/utils/location.ts-- passesnpx prettier --check app/utils/location.ts-- passesapp/utils/location.tsto update.Replaces #1471, which was opened from a fork and hit an unrelated CI failure (test_e2e can't authenticate to GCP for
pull_requestruns from forks, since GitHub doesn't pass repo secrets to fork-originated PR workflows). This PR is pushed directly to a branch on this repo instead, so CI (including e2e) runs normally with full secrets access.