NativeScript / nativescript-geolocation

Geolocation plugin to use for getting current location, monitor movement, etc
Apache License 2.0
139 stars 77 forks source link

enableLocationRequest() not working on Android #266

Closed dahlrad333 closed 3 years ago

dahlrad333 commented 3 years ago

My application seems to think it already has location from android

My Nativescript-Angular application has been using this nativescript-geolocation plugin reliably for a while, but only recently did I notice incorrect functionality in android. The methods don't seem to effectively communicate to the OS that the app is requesting location service permission.

Platform

Versions

Recreate the Issue

The application contains a few features that become available only when location permissions are given to the application, but to optimize UX, we have included a permissions primer to delegate the execution of the native location permission request to the user. It shows a more themed request for allowance of native location to calculate and then provide some of those other features. The permissions primer component is set up as the default route, whose logic

However, this plugin no longer seems to be allowing the application to ask for permission for anything. Even after uninstalling from my device and rebuilding, all permissions were denied, yet the geolocation plugin was returning that location services WERE enabled. This of course resulted in poor functionality. After looking into a fix, this npm package seemed viable. It's named '''@nativescript/geolocation''', not to be confused with this repository's '''nativescript-geolocation'''. And unfortunately it doesn't have much documentation as it seems to have been published only a few weeks ago. It does however, contain all the same methods as '''nativescript-geolocation''', so after switching the plugin source the application was finally able to initialize that native location permission request '''enableLocationRequest()''', but only on android, as the same issue started happening on iOS; No prompt, no permissions granted, app thought location services were enabled and logged all the errors from distance calculations without a starting point. Furthermore, on android, it wasn't even able to calculate the devices current location. It seems to only enable location services, but is not providing a variable at some point that returns an error: '''' Cannot enable location services: cannot read property 'Accuracy' of undefined ''' So, what ended up being a janky frankenstein fix was only on android, using only '''enableLocationRequest()''' from '''@nativescript/geolocation''' and then relying on this '''nativescript-geolocation''' for everything else, as it still works well. However, I would like to be reliant on only one plugin for all my geolocation needs, so I came to the source to get some help.

Code Demo & Potential Fix

Upon downloading the demo for geolocation and getting it to build on android, the enable location works perfectly. This makes me wonder what it is about my implementation that had issues with reaching the operating system for the location permission request. In order to successfully build the demo on my device, I needed to 'update' the android platform as per this thread, which may be the only thing I need to do for my application to communicate with android as well. If not, I also have a working code demo to go off of, so hopefully I can get this fixed in the process of creating a code demo to showcase my problem.

dahlrad333 commented 3 years ago

Closing this because it seems to be working now. The demo's code worked for me and the only difference I could find between the changes was that enableLocationRequest wasn't being called as a string of promises after the isEnabled(). I don't know why this was only the case on android. Problem resolved.