
在开发跑腿小程序的配送员派送页面时,我集成了小程序地图遇到一个坑,其中,includePoints在页面中使用正常,在组件中使用无效,success和fail也没有触发(页面里面有触发)。
:
css
<map id="map" style="width:100%;height:100%;position:fixed;top: 0;left: 0;right: 0;bottom: 0;" longitude="{{longitude}}" latitude="{{latitude}}"></map>
:
javascript
let mapC = wx.createMapContext('map');
console.log('======', mapC)
mapC.includePoints({
points: [{
"latitude": 30.259433598978386,
"longitude": 120.0117004409193
}, {
"latitude": 30.257973471323258,
"longitude": 120.0117003182772
}
padding: [10, 10, 10, 10], // 设置视野边距
success: (res) => {
console.log('res', res)
},
fail: (err) => {
console.log('err', err)
}
经结合文档MapContext | 微信开放文档,进行排查,发现:
组件中创建需要加一个this。
ini
let mapC = wx.createMapContext('map', this);

在代码加上:

发现可以了:

