bug: Geolocation Throws An Error If Device Location Services Disabled
See original GitHub issueBug Report
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 3.5.1
@capacitor/core: 3.5.1
@capacitor/android: 3.5.1
@capacitor/ios: 3.5.1
Installed Dependencies:
@capacitor/cli: 3.5.0
@capacitor/android: 3.5.0
@capacitor/ios: 3.5.0
@capacitor/core: 3.5.0
[success] iOS looking great! 👌
[success] Android looking great! 👌
The latest @capacitor/geolocation is installed, 1.3.1
Platform(s)
- iOS
- I am unable to confirm or deny if it occurs on Android
Current Behavior
- If the device has ‘Location Services’ disabled within Settings
- And you request requestPermissions() and/or checkPermissions()
- It will throw an error
Expected Behavior
- I would expect it to return a PermissionStatus of ‘denied’
- I would not expect it to throw an error and have to handle it differently.
- Error message returned is {message: “Location services are not enabled”, errorMessage: “Location services are not enabled”}
Code Reproduction
- Call either methods below while running on a real world iOS device
- It occurs regardless of destructuring the assignment or not
- const { location } = await Geolocation.checkPermissions();
- const { location } = await Geolocation.requestPermissions({ permissions: [‘location’] }); OR
- await Geolocation.checkPermissions();
- await Geolocation.requestPermissions();
Other Technical Details
npm --version
output: 6.14.16
node --version
output: v14.19.0
pod --version
output (iOS issues only): 1.11.2
Additional Context
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Troubleshooting Geolocation Errors - Texas State Law Library
Go to Settings > Location on your phone and make sure one or both of these options is on. If they were enabled...
Read more >Error Messages | Maps JavaScript API - Google Developers
This behavior typically indicates issues with either an API key or billing. In order to use Google Maps Platform products, billing must be...
Read more >cordova-plugin-geolocation
This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning ...
Read more >My tracker is reporting inaccurate GPS positions - what can I do?
In this article, we explain all reasons why you might see inaccurate location data from time to time in the Tractive GPS app,...
Read more >Use Location Services for Alexa Skills - Amazon Developer
To determine whether the customer's device can share location, check whether the context.System.device.supportedInterfaces object has a Geolocation field. If ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have to open the location setting manually and show it to the user to enable it, it won’t show the GPS popup
catch (error) { if (error.message === 'location disabled') { return NativeSettings.open({ optionAndroid: AndroidSettings.Location, optionIOS: IOSSettings.LocationServices, }); } }
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.