0

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

As suggested in one of the previous answer, you can directly mention desiredAcccuracy as 3, and make sure you are using correct version of location dependency in your app.gradle. (21.0.0 latest stable version)

dependencies {
 // compile 'com.google.android.gms:play-services:10.+'
  compile 'com.google.android.gms:play-services-location:21.0.0'
//  implementation 'androidx.multidex:multidex:2.0.1'
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.