Skip to content

Conversation

@nilayarya
Copy link
Owner

@nilayarya nilayarya commented Mar 30, 2025

Description of Change

Added a custom GeolocationSystemPermissionManager that wraps the existing one in electron to make geolocation requests.
Serves as an alternative API to navigator.geolocation that many users are facing issues with to make location requests on macOS. The implementation includes macOS geolocation permission handling as well.

Fixes: electron#45290

This fork is a working solution for some of the common geolocation needs of apps. It covers requesting and getting current position (latitude, longitude).

Electron v37.0.0

Use the following APIs:

electron.geolocation.requestPermission()

Note

Request Permission prompt will open only the first time a geolocation request is made. Subsequent calls will open System Settings (Location Services tab).

Image

Once your app has permission, you can retrieve the current position with:

await electron.geolocation.getCurrentPosition()

Note

Calling this without geolocation permission will return {latitude : 0, longitude : 0}

Image

You may build it yourself and give it a try! If you run into issues, report them in the issues tab of the fork 🚀

Implementation:

The new GeolocationSystemPermissionManager essentially uses a wrapped version of the SystemGeolocationSourceApple class, the same GeolocationSystemPermissionManager handed over to device service during startup. This change was essential because only a single instance of CLLocationManager can exist (as previously used in SystemGeolocationSourceApple), and multiple instances would lead to a crash.

Summary:

Extended SystemGeolocationSourceApple to SystemGeolocationSourceAppleCustom and initialized the CLLocationManager inside it before passing it to the device service.

Added utility functions to request permission and retrieve the current geolocation under the extended SystemGeolocationSourceAppleCustom

Provided an API to call these functions from main and rendered process

Checklist

Release Notes

Notes: Added a custom geolocation manager for electron. Provides a way to request for geolocation access

@spbgzh
Copy link

spbgzh commented Apr 19, 2025

Can u add a build version, please.

@nilayarya
Copy link
Owner Author

Can u add a build version, please.
Electron v37.0.0

@nilayarya nilayarya changed the title feat(macOS):request and get current position api feat(macOS): request and get current position api Apr 19, 2025
@nilayarya nilayarya changed the title feat(macOS): request and get current position api feat: request and get current position api for macOS Apr 19, 2025
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.

How to trigger the system geolocation prompt in a MAS (Mac App Store) build on macOS?

3 participants