先看代码
<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": "你的位置信息将用于小程序位置接口的效果展示"
}
},