<template>
<view class="content">
<map id="maps" style="width: 750rpx;height: 100vh;" :latitude="latitude" :longitude="longitude" :markers="markers" :polyline="polylines" scale="10"></map>
</view>
</template>
<script>
export default {
data() {
return {
latitude: '',
longitude: '',
markers:[],
polylines:[]
}
},
onReady() {
this.getlocal();
this.test();
},
methods: {
test(){
var that = this;
that.polylines = [{
points: [{
latitude: 29.79396,
longitude: 119.6913
},
{
latitude: 29.79357,
longitude: 119.6915
},
{
latitude: 29.79365,
longitude: 119.6914
},
{
latitude: 29.79305,
longitude: 119.6919
},
{
latitude: 29.79315,
longitude: 119.6916
}
],
arrowLine: true,
dottedLine: true,
width: 2,
color: "FEAA34"
}];
that.markers = [{
title: '123',
latitude: 29.79396,
longitude: 119.6913,
},
{
title: '123',
latitude: 29.79357,
longitude: 119.6915,
},
{
title: '123',
latitude: 23.03528,
longitude: 113.149565,
},
{
title: '123',
latitude: 29.79365,
longitude: 119.6914,
},
{
title: '123',
latitude: 29.79315,
longitude: 119.6916,
},
];
},
getlocal: function() {
let _this = this;
var map = uni.createMapContext('maps', this).$getAppMap();
map.showUserLocation(true);
uni.getLocation({
type: 'wgs84',
success: function(res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
_this.longitude = res.longitude;
_this.latitude = res.latitude;
}
})
},
}
}
</script>
<style scoped lang="scss">
.content {
// position: absolute;
width: 100vw;
height: 100vh;
}
</style>