plugins icon indicating copy to clipboard operation
plugins copied to clipboard

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

Open sasabogi opened this issue 2 years ago • 4 comments

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"

sasabogi avatar Dec 20 '22 10:12 sasabogi

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?

CatchABus avatar Dec 22 '22 12:12 CatchABus

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

Semurak avatar Dec 29 '22 09:12 Semurak

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.

overwise avatar Mar 12 '23 08:03 overwise

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.

CatchABus avatar Mar 12 '23 12:03 CatchABus