You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.7 KiB
97 lines
2.7 KiB
<template>
|
|
<view>
|
|
<view class="button-box">
|
|
<button size="mini" type="primary" @click="getLocations">开始记录</button>
|
|
<button size="mini" type="primary" @click="stopLocation">停止记录</button>
|
|
<button size="mini" type="primary" @click="uploadData">提交记录</button>
|
|
</view>
|
|
<map :scale="3" :longitude="lon" :latitude="lat" style="width: 100%; height:100vh" :polyline="locationss"></map>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
arrs:[],
|
|
lon: 114.57,
|
|
lat: 38.04,
|
|
locationss: [
|
|
{
|
|
points: [],
|
|
color: '#0000AA',
|
|
width: 10,
|
|
arrowLine: true
|
|
},
|
|
{
|
|
points: [
|
|
{ latitude: 38.044231770833335, longitude: 115.56865288628472 },
|
|
{ latitude: 39.044231770833335, longitude: 116.56865288628472 },
|
|
{ latitude: 40.044231770833335, longitude: 117.56865288628472 },
|
|
{ latitude: 41.044231770833335, longitude: 118.56865288628472 },
|
|
{ latitude: 42.044231770833335, longitude: 119.56865288628472 },
|
|
{ latitude: 43.044231770833335, longitude: 120.56865288628472 }
|
|
],
|
|
width: 10,
|
|
color: '#00aa29',
|
|
arrowLine: true
|
|
}
|
|
],
|
|
};
|
|
},
|
|
methods:{
|
|
getLocations() {
|
|
let this_ = this;
|
|
uni.startLocationUpdate({
|
|
success: function (res) {
|
|
console.log(res, '开启小程序接收位置消息成功');
|
|
uni.onLocationChange(function (res) {
|
|
console.log(res);
|
|
console.log('纬度:' + res.latitude);
|
|
console.log('经度:' + res.longitude);
|
|
let lng = res.longitude.toFixed(2);
|
|
let lat = res.latitude.toFixed(2);
|
|
this_.arrs.push({ latitude: res.latitude, longitude: res.longitude });
|
|
console.log(this_.arrs,'1' )
|
|
this_.locationss[0].points = this_.arrs;
|
|
this_.locationss = [...this_.locationss];
|
|
console.log(this_.locationss ,'2')
|
|
});
|
|
|
|
},
|
|
fail: (err) => console.error('开启小程序接收位置消息失败:', err),
|
|
complete: (msg) => console.log('调用开启小程序接收位置消息 API 完成')
|
|
});
|
|
},
|
|
updateLocation() {
|
|
uni.onLocationChange(function (res) {
|
|
console.log('纬度:' + res.latitude);
|
|
console.log('经度:' + res.longitude);
|
|
});
|
|
},
|
|
stopLocation() {
|
|
let this_ = this;
|
|
uni.stopLocationUpdate({
|
|
success: (res) => console.log('关闭成功', this_.locationss),
|
|
fail: (err) => console.error('关闭失败:', err),
|
|
complete: (msg) => console.log('调用开启小程序接收位置消息 API 完成')
|
|
});
|
|
},
|
|
uploadData(){
|
|
console.log(this.locationss)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.button-box{
|
|
display: flex;
|
|
justify-content: space-around;
|
|
position: fixed;
|
|
z-index: 999;
|
|
width: 100%;
|
|
top: 100rpx;
|
|
}
|
|
</style>
|
|
|