uniapp地图-标记点-多点连线

前言:正在使用uniapp开发地图这块不明白的小伙伴可以看看我以下的代码分享;下面是我开发中使用vue+uniapp遇到的地图问题,有的APP涉及到地理位置的功能,所以,地图组件可以实现这个功能,如:调起手机的第三方导航(百度地图、高德地图)、在地图上标记出来每个不同的定位,也可以让相同类型的标记点相连并设置不同的图片和颜色更好的辨认。

PS:下面我跟大家分享是地图标记点和标记点相连;注释已经写在代码里面的,代码易懂,表达不清楚或者有什么问题可以评论~


uniapp地图-点击添加标记点

uniapp地图-删除标记点

uniapp子窗体的使用与传参


正在加载。。。。

PS:先上效果图


图1:标记点
在这里插入图片描述


图2:标记点相连
在这里插入图片描述


.vue代码文件

PS:以上效果便是下面代码执行之后的,这里要注意复制过去注意图片路径

<template>
	<view class="content">
		<!-- 在map标签绑定经纬度和标记点数组,以及连线数组 -->
		<map id="maps" :latitude="latitude" :longitude="longitude" :markers="markers" :polyline="polylines" scale="10"></map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: '',//纬度
				longitude: '',//经度
				markers:[],//标记点数组
				polylines:[]//连续数组
			}
		},
		onReady() {
			//调用的函数放到onReady里面
			this.getlocal();
			this.test();
		},
		methods: {
			//地图标记点;   具体的属性可以看看官网的说明
			test(){
				var that = this;
				//地图标记点连线静态数据赋值;
				// 可以理解成下面polylines里面的一个对象为一条线,每一条线都是独立的,可以设置不同的连续颜色
				//points[]里面是从第一个对象连到最后一个对象的经纬度成一条线
				that.polylines = [{
					points: [{
							latitude: 23.043594,
							longitude: 113.160704
						},
						{
							latitude: 23.036344,
							longitude: 113.160704
						},
						{
							latitude: 23.03528,
							longitude: 113.149565
						},
						{
							latitude: 23.03794,
							longitude: 113.138498
						},
						{
							latitude: 23.049247,
							longitude: 113.145684
						}
					],
					arrowLine: true,
					dottedLine: true,
					arrowIconPath: "/static/images/2btn_loc/btn_loc3.png",
					width: 2,
					color: "FEAA34"
				}];
				//地图标记点静态数据赋值;
				//标记点和连线的意思差不多,标记点的数组是单纯将markers数组中的对象的经纬度通过图片的方式标记出来(图片可以自定义)
				that.markers = [{
						title: '123',
						latitude: 23.043594,
						longitude: 113.160704,
						iconPath: '/static/btn_loc0.png'
					},
					{
						title: '123',
						latitude: 23.036344,
						longitude: 113.160704,
						iconPath: '/static/btn_loc0.png'
					},
					{
						title: '123',
						latitude: 23.03528,
						longitude: 113.149565,
						iconPath: '/static/btn_loc0.png'
					},
					{
						title: '123',
						latitude: 23.03794,
						longitude: 113.138498,
						iconPath: '/static/btn_loc0.png'
					},
					{
						title: '123',
						latitude: 23.049247,
						longitude: 113.145684,
						iconPath: '/static/btn_loc0.png'
					},
				];
			},
			//定位方法;获取当前的经纬度,也可以通过经纬度来获取当前的地理位置,比如:xx省、xx市、xx镇
			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: 100%;
		height: 100%;

		#maps {
			width: 100%;
			height: 100%;
		}
	}
</style>
  • 8
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 49
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 49
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值