Turbo-iOS App - Geolocation

Is it possible to use iOS geolocation settings with Javascript navigator.geolocation?

When my app opens for the first time, 3 different permission popups are displayed.

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(displayAndWatch, locError, {
    enableHighAccuracy: false,
    timeout: 8000,
    maximumAge: 1000
  });
} else {
  alert("Your device does not support geolocation.");
}
  1. Allow access to Motion and Orientation (Javascript)
  2. Allow the app to use current location (Javascript)
  3. Location popup with (Never, Ask Next Time, While Using the App) - iOS

Ideally, I’d just have the traditional iOS popup that, once answered, would be used by Javascript so the user didn’t get so many redundant prompts.

One thought I’ve had on managing this is letting iOS manage the location data and then pass lat/lon and heading data to javascript to place the marker on the map.

Is there a way to pass data from iOS to javascript to make this happen?

I was able to get this working with a Bridge Component. iOS sends the lat, lon, and heading. I skip the JS geolocation code when receiving the data from iOS so it works in the app and browser just fine.

The basis for this came from Joe Masilotti’s Bridge Components. The Pro location component was a huge help - A library of bridge components for Hotwire Native apps | Masilotti.com