geolocationnativescriptnativescript-vue

Error: Cannot enable the location service. TypeError: Cannot read property 'Accuracy' of undefined


I'm trying to use @nativescript/geolocation in nativescript-vue android app. By calling the getCurrentLocation method as shown in the code below.

import * as geolocation from '@nativescript/geolocation'
import { CoreTypes } from '@nativescript/core'
CoreTypes.Accuracy // used to describe at what accuracy the location should be get
...
methods: {
    onLoaded(){
        console.log('>>>>>>>>>>>>>>> : loaded ')
        geolocation.getCurrentLocation({
            desiredAccuracy: Accuracy.high,
            maximumAge: 5000,
            timeout: 20000
        })
        .then(res => {
            console.log('LOACATION >>>>>>>>>>.>>>>> : ', res)
        })
        .catch(err => {
            console.log('LOACATION ERROR >>>>.>>>>> : ', err)
        })
    }
}

I get this error : Error: Cannot enable the location service. TypeError: Cannot read property 'Accuracy' of undefined

I also try to use tns-core-modules instead of '@nativescript/core'

import { Accuracy } from "tns-core-modules/ui/enums";

But it doesn't work


Solution

  • For anyone still looking for a solution to this, I was able to find was using CoreTypes.Accuracy.high

    geolocation.getCurrentLocation({
                desiredAccuracy: CoreTypes.Accuracy.high,
                maximumAge: 5000,
                timeout: 20000
            })
    

    The number value of high also equals 3. So desiredAccuracy: 3 is also valid