【问题标题】:Error: Cannot enable the location service. TypeError: Cannot read property 'Accuracy' of undefined错误:无法启用定位服务。类型错误:无法读取未定义的属性 \'Accuracy\'
【发布时间】:2022-08-05 00:33:38
【问题描述】:

我正在尝试在nativescript-vue android 应用程序中使用@nativescript/geolocation。通过调用 getCurrentLocation 方法,如下面的代码所示。

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)
        })
    }
}

我收到此错误:Error: Cannot enable the location service. TypeError: Cannot read property \'Accuracy\' of undefined

我也尝试使用 tns-core-modules 而不是 \'@nativescript/core\'

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

但它不起作用

    标签: geolocation nativescript nativescript-vue


    【解决方案1】:

    对于仍在寻找解决方案的任何人,我发现正在使用CoreTypes.Accuracy.high

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

    high 的数值也等于3。 所以desiredAccuracy: 3 也是有效的

    【讨论】:

      猜你喜欢
      • 2021-11-08
      • 2021-11-04
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2017-08-12
      • 2021-12-03
      相关资源
      最近更新 更多