<template>
<view>
<map :latitude="latitude" :longitude="longitude" scale="14" :polyline="polyline" :markers="markers"></map>
</view>
</template>
<script>
export default {
data() {
return {
latitude: 39.8888726387478,
longitude: 116.40099038098143,
currentPath: {
latitude: null,
longitude: null
},
markers: [{
id: 1,
//纬度
latitude: 39.8888726387478,
//经度
longitude: 116.40099038098143,
iconPath: "../../static/logo.png",
width: 15,
height: 15,
// title:"芭比歪不",
label: {
content: '起点',
color: '#ff0000'
}
// callout:{
// // content:'歪比巴卜',
// // color:'#ff0000'
// }
},
{
id: 2,
//纬度
latitude: 39.91481538744656,
//经度
longitude: 116.37455452893064,
iconPath: "../../static/logo.png",
width: 20,
height: 20,
label: {
content: '终点',
color: '#ff0000'
}
},
{
id: 3,
//纬度
latitude: null,
//经度
longitude: null,
iconPath: "../../static/logo.png",
width: 15,
height: 15,
// title:"芭比歪不",
label: {
content: '当前位置',
color: '#ff0000'
}
// callout:{
// // content:'歪比巴卜',
// // color:'#ff0000'
// }
},
],
polyline: [{
points: [{
latitude: 39.8888726387478,
longitude: 116.40099038098143
}, {
latitude: 39.91481538744656,
longitude: 116.37455452893064
}],
color: "#31c27c",
width: 10,
arrowLine: true,
borderWidth: 2
},
{
points: [
{
latitude: 39.8888726387478,
longitude: 116.40099038098143
},{
latitude: null,
longitude: null
}],
color: "#04A7FB",
width: 10,
arrowLine: true,
borderWidth: 2
}]
}
},
created() {
//获取权限
// #ifdef MP-WEIXIN
uni.authorize({
scope: 'scope.userLocation',
success: res => {
uni.getLocation({
success: res => {
console.log(res)
console.log('纬度:' + res.latitude);
console.log('经度:' + res.longitude);
this.markers.forEach(item => {
if (item.id === 3) {
item.latitude = res.latitude;
item.longitude = res.longitude;
}
});
this.polyline[1].points[1].latitude= res.latitude;
this.polyline[1].points[1].longitude= res.longitude;
console.log(this.currentPath)
}
});
}
})
//#endif
}
}
</script>
<style lang="scss" scoped>
map {
width: 100vw;
height: 100vh;
}
</style>
uniapp中使用map组件 查看地图线路
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 开发思路[https://hurely.github.io/2020/10/06/post33/#%E5%BC%8...