Only trigger geolocation permission prompt on explicit "my location" click - #30
Merged
Merged
Conversation
Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix location permission dialog in Chrome mobile
Only trigger geolocation permission prompt on explicit "my location" click
Sep 1, 2026
mmathieum
approved these changes
Sep 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents the browser’s geolocation permission prompt from appearing automatically on index.html page load by only using navigator.geolocation when permission is already granted, and otherwise falling back to IP-based centering.
Changes:
- Update
centerMapOnDeviceLocation(map)to query the Permissions API and only callgetCurrentPosition()when the geolocation permission state isgranted. - For
prompt/denied/ Permissions API unsupported cases, skipnavigator.geolocationentirely on load and fall back toipwho.is, with a default-center fallback on failure.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
On
index.html, loading the map page auto-triggered Chrome mobile's location permission dialog, even though the user hadn't interacted with the "my location" button.Root cause
centerMapOnDeviceLocation()ran on pageloadand calledcenterMapOnDeviceLocationNavigator(), which invokednavigator.geolocation.getCurrentPosition()unconditionally.navigator.permissions.query()check only short-circuited for thedeniedstate; the defaultpromptstate still fell through togetCurrentPosition(), surfacing the native permission dialog on every load.Fix
centerMapOnDeviceLocation()now checks the Permissions API result before deciding how to center the map on load:granted→ usenavigator.geolocationdirectly (no dialog, since permission is already resolved).prompt,denied, or Permissions API unsupported) → skipgetCurrentPosition()entirely and fall back to IP-based geolocation (ipwho.is), silently, with no dialog.requestDeviceLocation) is unchanged — clicking it still explicitly callsgetCurrentPosition()and can prompt for permission, as intended./index.htmlstill request 🛰️ location permission & show dialog 🗯️ in Chrome mobile #29