mapcontext.includepoints(object object)
基础库 或更高版本; 且 支付宝客户端 10.2.0 或更高版本; 若版本较低,建议采取 兼容处理 。
小程序开发者工具: 不支持。
主体: 企业支付宝小程序 、 个人支付宝小程序
调整地图可视区域以包含指定的坐标点。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 描述 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
points | array | - | 是 | 要显示在可视区域内的坐标点列表 |
||||||||||
|
||||||||||||||
padding | array |
[0,0,0,0] | 否 | 坐标点形成的多边形边缘到地图边缘的距离。格式为 [上,右,下,左],如果数据只有一项,则上下左右的 padding 一致 |
||||||||||
success | function | - | 否 | 调用成功的回调函数 |
||||||||||
fail | function | - | 否 | 调用失败的回调函数 |
||||||||||
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | 接口参数无效 |
请填写正确类型的参数。 |
mapcontext.includdepoints axml 代码
mapcontext.includdepoints js 代码
success 参数
<view>
<map id="map" style="width:100%; height:500px"/>
<button ontap="includepoints">开始改变地图视野</button>
</view>
page({
data: {
mapctx: null,
},
onready() {
this.mapctx = my.createmapcontext("map");
},
includepoints() {
this.mapctx.includepoints({
points: [
{
latitude: 39.935029,
longitude: 116.384377,
},
{
latitude: 39.939577,
longitude: 116.388331,
},
],
padding: [48, 48, 48, 48],
success: (res) => {
console.log("success", res);
},
fail: (error) => {
console.log("fail", error);
},
});
},
});
{
success: true
}
-
bug安卓 10.3.70 之前的版本未校验 points 为空的情况。若 points 为空值,安卓会走 success 回调函数并返回
success: true
。使用 api 时请确保给必填参数赋值。 -
bug支付宝 10.3.70 之前的版本未校验参数 padding 类型是否正确。若 padding 类型错误,ios 会执行 success 回调函数并返回
success: true
,安卓会报错误码 3 提示未知错误。使用 api 时请确保 padding 类型正确。 -
tip如果传入过多的经纬度点给 points,可能会导致地图卡顿甚至崩溃。为了避免上述问题,可以只给 points 提供可视区域内最大经纬度和最小经纬度构成的坐标点,通过两点来确定可视范围。