使用 mapContext的translateMarker,在调试工具和安卓手机上Marker都可以正常移动到服务器传过来的地理定位,但是ios上就会经常报出errMsg:"translateMapMarker:fail invalid markerid",偶尔也可以正常显示,一下是部分关键代码,请大神指教一下。
map组件
< map id = "mymap" longitude = "{{mapLon}}" latitude = "{{mapLat}}" markers = "{{markers}}" scale = "14" > map> |
markers
markers: [{ iconPath: '../assets/image/icon_map_location.png' , id: 0, latitude: 0, longitude: 0, width: 12, height: 16 }] |
translateMarker
translateMarker (lat, lon) { lat = parseFloat(lat) lon = parseFloat(lon) const self = this self.mapCtx = wx.createMapContext( 'mymap' ) self.mapCtx.translateMarker({ markerId: 0, autoRotate: false , duration: 1000, destination: { latitude: lat, longitude: lon }, animationEnd () { console.log( 'animation end' ) }, fail (err) { console.log(err) } }) } |
什么时机调用translateMarker,麻烦提供一下完整一点的代码
@黄思程
不清楚为什么会这样 ,但是如果是在chooseLoacation.then里面调用 就有可以正常显示
self.chooseLocation().then(res => {
self.mapLon = res.longitude
self.mapLat = res.latitude
console.log(
'为空self.mapLon:'
,self.mapLon)
self.translateMarker(+res.latitude, +res.longitude)
self.mapMask.bg =
'rgba(0,0,0,0)'
self.mapMask.none =
'none'
self.$apply()
})
getCardInfo ($id) {
const self =
this
wepy.request({
method: api.cardBseInfo.method,
url: api.cardBseInfo.url,
// data: {card_id: $id, simple: 1},
data: {card_id: $id},
header: {
token: self.token,
appname:
'weappInvitationCard'
}
}).then(res => {
let resObj = res.data.data
let timeArr = resObj.time.split(
' '
)
let hoursMin = timeArr[1].substr(0, 5);
let lat = self.mapLat = resObj.latitude
let lon = self.mapLon = resObj.longtitude
// let lat = self.editorPageLat = resObj.latitude
// let lon = self.editorPageLon = resObj.longtitude
self.groom_val = resObj.groom_name
self.bride_val = resObj.bride_name
self.wed_add_val = resObj.place
self.front_page_id = resObj.front_page.id
self.speech_page_id = resObj.speech_page.id
self.front_page_imgArr = resObj.front_page.images
self.speech_page_imgArr = resObj.speech_page.images
console.log(resObj.front_page.images,self.front_page_imgArr)
self.date = timeArr[0]
self.time = hoursMin
self.positionIcon =
'16px'
self.positionIconBlock =
'block'
self.mapMask.parentNone =
'block'
self.mapMask.bg =
'rgba(0,0,0,0)'
self.mapMask.none =
'none'
self.theme_id = resObj.theme_id
self.editorCardMode =
true
self.translateMarker(parseFloat(lat), parseFloat(lon))
self.$apply()
})
}
translateMarker (lat, lon) {
const self =
this
self.mapCtx = wx.createMapContext(
'mymap'
)
self.mapCtx.translateMarker({
markerId: 0,
autoRotate:
false
,
duration: 1000,
destination: {
latitude: lat,
longitude: lon
},
animationEnd () {
console.log(
'animation end'
)
},
fail (err) {
console.log(
'ni ma'
)
console.log(err)
}
})
}
ios11 微信6.6.3 为什么从服务器获取经纬度信息,在移动translateMarker会显示 invalid markerid
不是一直没有,是时有时无,很郁闷