NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
189 stars 107 forks source link

[@nativescript/geolocation] getCurrentLocation() not working in NS8 #384

Open sasabogi opened 1 year ago

sasabogi commented 1 year ago

getCurrentLocation() returned an error in NativeScript 8: Error: Cannot enable the location service. TypeError: Cannot read property 'Accuracy' of undefined

I'm using the latest version "@nativescript/geolocation": "8.1.0"

CatchABus commented 1 year ago

getCurrentLocation() returned an error in NativeScript 8: Error: Cannot enable the location service. TypeError: Cannot read property 'Accuracy' of undefined

I'm using the latest version "@nativescript/geolocation": "8.1.0"

Which platform?

Also, Accuracy is an enum in CoreTypes module. There is a chance you face a circular reference problem or something like that. Can you try updating core package to 8.4?

Semurak commented 1 year ago
Error: Cannot enable the location service. TypeError: Cannot read property 'PRIORITY_HIGH_ACCURACY' of undefined
  JS:     at file:///data/data/de.xxx.android/files/app/vendor.js:55032:32
  JS:     at _ZoneDelegate.invoke (file:///data/data/de.xxx.android/files/app/vendor.js:132239:26)
  JS:     at Object.onInvoke (file:///data/data/de.xxx.android/files/app/vendor.js:180167:33)
  JS:     at _ZoneDelegate.invoke (file:///data/data/de.xxx.android/files/app/vendor.js:132238:52)
  JS:     at Zone.run (file:///data/data/de.xxx.android/files/app/vendor.js:132001:43)
  JS:     at file:///data/data/de.xxx.android/files/app/vendor.js:133142:36
  JS:     at _ZoneDelegate.invokeTask (file:///data/data/de.xxx.android/files/app/vendor.js:132273:31)
  JS:     at Object.onInvokeTask (file:///data/data/de.xxx.android/files/app/vendor.js:180154:33)
  JS:     at _ZoneDelegate.in...

I'm running into the same problem. It happens on Android with NS Core 8.4

Edit: Nevermind, found the answer here https://github.com/NativeScript/plugins/issues/364

overwise commented 1 year ago

Hi, This problem still exists, and in my case it's not about googlePlayServicesVersion. As the original issue states:Cannot read property 'Accuracy' of undefined is the reason for failure, which is different from #364 case.

In my case, geolocation is not necessary for the functionality in my app, so I just cannot afford to waste any more of my time on this, but here is another clue I found that might help someone in debugging.

For me, iOS fails regardless of any of this with the message Error: The operation couldn’t be completed. (kCLErrorDomain error 0.) (at least in simulator) so I'm talking only about Android here.

Android works if I do not specify desiredAccuracy inside getCurrentLocation() options at all, or provide a number, going around CoreTypes.

So

geolocation.enableLocationRequest().then(() => {
      geolocation
        .getCurrentLocation({
          desiredAccuracy: 1,
          maximumAge: 5000,
          timeout: 20000
        })
        .then(currentLocation => {
          console.log('My current latitude: ', currentLocation.latitude)
        })
    })

works.

CatchABus commented 1 year ago

Hi, This problem still exists, and in my case it's not about googlePlayServicesVersion. As the original issue states:Cannot read property 'Accuracy' of undefined is the reason for failure, which is different from #364 case.

In my case, geolocation is not necessary for the functionality in my app, so I just cannot afford to waste any more of my time on this, but here is another clue I found that might help someone in debugging.

For me, iOS fails regardless of any of this with the message Error: The operation couldn’t be completed. (kCLErrorDomain error 0.) (at least in simulator) so I'm talking only about Android here.

Android works if I do not specify desiredAccuracy inside getCurrentLocation() options at all, or provide a number, going around CoreTypes.

So

geolocation.enableLocationRequest().then(() => {
      geolocation
        .getCurrentLocation({
          desiredAccuracy: 1,
          maximumAge: 5000,
          timeout: 20000
        })
        .then(currentLocation => {
          console.log('My current latitude: ', currentLocation.latitude)
        })
    })

works.

Then you should pay more attention to my first answer instead: https://github.com/NativeScript/plugins/issues/384#issuecomment-1362791180 This error indicates your environment cannot resolve CoreTypes so it might be that you're using a @nativescript/core version that is no longer compatible or has problems with current version of plugin.