小程序定位 事件 点击事件 地图放回当前所在点

小程序打开地图 滑动地图之后 展示位置不在当前定位出  ,点击事件 触发地图返回当前定位点

如下

地图展示组件  注意  show-location设置为true

<map id="Map" :markers="markers" @markertap="markertap" style="width:750rpx;height:100vh;"
			:longitude="longitude" :latitude="latitude" scale='16' show-location>
		</map>

准备事件  找到地图组件

onReady() {
			
			this.mapCtx = wx.createMapContext('Map');
}

  重新定位按钮 及绑定事件

<view class="rePosition" @click="rePosition">
				<view class="positionFont">重新定位</view>
</view>

定位事件  重点 使用this.mapCtx.moveToLocation() 

rePosition(e) {
				//this.getMyLocation() //获取当前采样点经纬度事件
				this.mapCtx.moveToLocation() //地图回到当前位置
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值