组件代码
<uni-popup ref="mapPopup" type="center">
<view class="map-box">
<view>xxx</view>
<map ref="pointMap" id="pointMap" style="width: 300px; height: 400px;" :latitude="39.909" :longitude="116.39742"
:markers="mapCenterMarkers" @regionchange="updatedMap" @markertap="tapMarker"></map>
</view>
</uni-popup>
// JS 代码
data() {
return {
mapCenterMarkers: [{
longitude: 116.39, latitude: 39.90,
id: 1,
iconPath: '/static/location.png'
}]
}
}
popup 打开时初始化 mapContext
openMapPopup() {
this.$refs.mapPopup.open()
this.$nextTick(() => {
if (!mapContext) {
mapContext = uni.createMapContext('pointMap', this)
}
})
},
地图移动时更新 marker 位置
updatedMap(e) {
if (e.type == 'begin') {
return console.log('begin updated', e)
}
console.log('updated map', e)
if (!e.detail.centerLocation) {
return console.warn('noCenterLocation', e.detail)
}
let {longitude, latitude} = e.detail.centerLocation
console.log('prepare update markers', longitude, latitude)
mapContext.translateMarker({
markerId: 1,
destination: {
latitude: 39.9365,
longitude: 116.389
},
autoRotate: false,
rotate: 0,
animationEnd: e => console.log('translateMarker animationEnd', e),
success: e => console.log('translateMarker success', e),
fail: e => console.log('translateMarker fail', e),
complete: e => console.log('translateMarker complete', e)
})
mapContext.getCenterLocation({
success: e => console.log('getCenterLocation', e)
})
console.log('this center markers')
},
5***@qq.com
问下怎么解决的
2023-03-21 16:10
7***@qq.com
出现同样的问题,是怎么解决的啊
2023-04-18 15:16
胜天半子祁厅长 (作者)
回复 7***@qq.com: 好像是高德、腾讯地图有差异,换了另外一个就好了
2023-04-19 20:03
胜天半子祁厅长 (作者)
回复 5***@qq.com: 好像是高德、腾讯地图有差异,换了另外一个就好了
2023-04-19 20:03