uniapp点击地图标记点,设置点击点为中心显示位置并放大层级

 先看代码

<map :style="{width: '750rpx',height: screenHeight+'px'}" id="map" :longitude="lng"
:latitude="lat":scale='scale' :markers="markers" @markertap="markertap"  
       @regionchange="regionchange":show-location="true"></map>	        

            // 放大层级
			enLargeZoom(ids) {
                //这里我拿到了标记点的id,我通过id进行筛选拿到当前点的经纬度
				let markerDetail = this.markers.filter(item => item.id === ids)[0]
                //创建map实例对象,创建好后使用map对象的moveToLocation方法;
                //createMapContext第一个参数为map组件的id,第二个参数传入组件实例this
                //使用此方法需要设置map组件属性 show-location=true
				uni.createMapContext('map', this).moveToLocation({
                    //将地图中心移动到当前定位点
					latitude: markerDetail.latitude,
					longitude: markerDetail.longitude
				})
				// 改变层级,map地图组件后台做了watch 需要改变scale的值才能放大层级
				if (this.scale != 17) {
					this.scale = 17;
				} else {
					this.scale = 16
				}
			},

   

使用moveToLocation时需要用于给予权限,在manifest.json文件中添加如下代码:

  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序位置接口的效果展示"
    }
  },

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值