【发布时间】:2020-06-25 14:51:48
【问题描述】:
在https://play.nativescript.org/ 上是一个名为Location 的组件,当在HelloWorld.vue 中使用它时,它如下所示,但是在我的房子周围移动并等待或按下Show location 按钮时位置不会改变/更新再次。我将 desiredAccuracy 和 updateDistance 都设置为 1 米,但在导入模块后也尝试使用值 Accuracy.high。可能是什么问题?
<template>
<Page>
<ActionBar title="Home" />
<ScrollView>
<StackLayout>
<Button text="Show location" @tap="enableLocationServices"/>
<StackLayout>
<Label :text="'Latitude: ' + currentGeoLocation.latitude" />
<Label :text="'Longitude: ' + currentGeoLocation.longitude" />
<Label :text="'Altitude: ' + currentGeoLocation.altitude" />
<Label :text="'Direction: ' + currentGeoLocation.direction" />
</StackLayout>
</StackLayout>
</ScrollView>
</Page>
</template>
<script>
const geoLocation = require("nativescript-geolocation");
export default {
methods: {
enableLocationServices: function() {
geoLocation.isEnabled().then(enabled => {
if (!enabled) {
geoLocation
.enableLocationRequest()
.then(() => this.showLocation());
} else {
this.showLocation();
}
});
},
showLocation: function() {
geoLocation.watchLocation(
location => { this.currentGeoLocation = location; },
error => { alert(error); },
{
desiredAccuracy: 1,
updateDistance: 1,
minimumUpdateTime: 1000 * 1
}
);
}
},
data() {
return {
currentGeoLocation: {
latitude: null,
longitude: null,
altitude: null,
direction: null
}
};
}
};
</script>
【问题讨论】:
-
您是否检查了您的位置设置?精度是否设置为高?您是否打开了 WiFi/移动数据和 GPS?
-
WiFi + GPS 已开启。精度设置为高是什么意思?哪个值设置为高?
标签: geolocation nativescript nativescript-vue