前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >案例一---位置共享---主次要人物定位

案例一---位置共享---主次要人物定位

作者头像
代码哈士奇
发布2021-02-04 11:09:34
3590
发布2021-02-04 11:09:34
举报
文章被收录于专栏:dmhsq_csdn_blogdmhsq_csdn_blog

说明

主要人物能看到所有人的位置 次要人物只能看到主要人物 次要人物会自动规划一条去主要人物的线路

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

主要人物

代码语言:javascript
复制
<template>
	<view>
		<map id="myMap" :markers="markers" style="width:100%;height:90vh;" :longitude="longitude" :latitude="latitude" scale='16'>
		</map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				markers: [{
					title: "主要",
					id: 11,

					latitude: 33.404659,
					longitude: 115.089099,
					label:{content:"主要",color:"#0000ff"},
					callout: {
						content: "主要",
						borderColor: 'blue'
					},
					iconPath: "../../../static/mainPeo.png"
				},{
					title: "普通1",
					id: 112,

					latitude: 33.403977,
					longitude: 115.088245,
					label:{content:"普通1",color:"#000000"},
					callout: {
						content: "普通1",
						borderColor: 'blue'
					},
					iconPath: "../../../static/somePeo.png"
				},{
					title: "普通2",
					id: 113,
					label:{content:"普通2",color:"#000000"},
					latitude: 33.404098,
					longitude: 115.087183,
					callout: {
						content: "普通2",
						borderColor: 'blue'
					},
					iconPath: "../../../static/somePeo.png"
				}],
				latitude: 33.404659,
				longitude: 115.089099
			}
		},
		methods: {

		}
	}
</script>

<style>

</style>

次要人物

代码语言:javascript
复制
<template>
	<view>
		<map id="myMap" style="width: 100%; height: 90vh" :markers="markers" :longitude="longitude" :latitude="latitude"
		 scale='18' :polyline="polyline" show-location>
		</map>
	</view>
</template>

<script>
	var QQMapWX = require('../../../common/qqmap-wx-jssdk.js')//根据自己的路径修改
	export default {
		data() {
			return {
				fromP: '33.403977,115.088245',
				toP: '33.404659,115.089099',
				longitude: 115.088245,
				latitude: 33.403977,
				polyline: [],
				markers: []
			}
		},
		onLoad() {
			this.test();
		},
		methods: {
			test() {
				let vm = this;
				var demo = new QQMapWX({
					key: '腾讯位置服务key腾讯位置服务官网获取'
				})
				demo.direction({
					mode: 'walking', //可选值:'driving'(驾车)、'walking'(步行)、'bicycling'(骑行),不填默认:'driving',可不填
					//from参数不填默认当前地址
					from: vm.fromP,
					to: vm.toP,
					success: res => {
						console.log(res)
						let ret = res;
						let coors = ret.result.routes[0].polyline;
						let pl = [];
						let kr = 1000000;
						//坐标解压(返回的点串坐标,通过前向差分进行压缩)
						for (var i = 2; i < coors.length; i++) {
							coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
						}
						//将解压后的坐标放入点串数组pl中
						for (var i = 0; i < coors.length; i += 2) {
							pl.push({
								latitude: coors[i],
								longitude: coors[i + 1]
							})
						}
						vm.latitude = pl[0].latitude
						vm.longitude = pl[0].longitude
						vm.polyline = [{
							points: pl,
							color: '#FF0000DD',
							width: 4
						}]
						let mks = []
						mks.push({
							title: "主要",
							id: 11,

							latitude: 33.404659,
							longitude: 115.089099,
							label: {
								content: "主要",
								color: "#0000ff"
							},
							callout: {
								content: "主要",
								borderColor: 'blue'
							},
							iconPath: "../../../static/mainPeo.png"
						}, {
							title: "普通1",
							id: 112,

							latitude: 33.403977,
							longitude: 115.088245,
							label: {
								content: "普通1",
								color: "#000000"
							},
							callout: {
								content: "普通1",
								borderColor: 'blue'
							},
							iconPath: "../../../static/somePeo.png"
						})
						vm.markers = mks
					}
				})
			}
		}
	}
</script>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-01-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 说明
  • 主要人物
  • 次要人物
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档