MapContext.getRegion
2020-08-26 16:37 更新
解释:获取当前地图的视野范围。
方法参数
Object object
object 参数说明
属性名 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | Function | 否 | 接口调用成功的回调函数,西南角与东北角的经纬度。 | |
fail | Function | 否 | 接口调用失败的回调函数 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明
参数 | 类型 | 说明 |
---|---|---|
southwest | Object | 西南角方向的经纬度 |
northeast | Object | 东北角方向的经纬度 |
示例
图片示例
代码示例
<view class="wrap">
<map id="myMap" style="width: 100%"></map>
<button type="primary" bindtap="getRegion">获取当前地图的视野范围</button>
</view>
Page({
onLoad() {
this.mapContext = swan.createMapContext('myMap');
},
getRegion() {
this.mapContext.getRegion({
success: res => {
swan.showModal({
title: '视野范围',
content: 'northeast: ' + JSON.stringify(res.northeast)
+ '/' + 'southwest: ' + JSON.stringify(res.southwest)
});
console.log('视野范围', res);
}
});
}
});
以上内容是否对您有帮助:
更多建议: