mapcontext.movetolocation(object object)
基础库 或更高版本; 且 支付宝客户端 10.1.32 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
小程序开发者工具: 支持。
主体: 企业支付宝小程序 、 个人支付宝小程序
移动地图中心位置。
可将地图中心移动到当前定位位置或任意经纬度。前者需要配合设置 map 组件的 show-location 属性(参见示例代码)。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 兼容性 | 描述 |
---|---|---|---|---|---|
latitude | number | - | 否 | 支付宝: 10.2.8 |
纬度,默认为当前定位纬度 |
longitude | number | - | 否 | 支付宝: 10.2.8 |
经度,默认为当前定位经度 |
success | function | - | 否 | - | 调用成功的回调函数 |
fail | function | - | 否 | - | 调用失败的回调函数 |
complete | function | - | 否 | - | 调用结束的回调函数(调用成功、失败都会执行) |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | 接口参数无效。 |
请将入参经纬度填写完整。 |
6000 | 未允许定位。 |
入参指定经纬度,或在 map 组件中添加 show-location。 |
mapcontext.movetolocation axml 代码
mapcontext.movetolocation js 代码
<view>
<map id="map" show-location style="width: 100%; height: 200px;">map>
<button ontap="movetolocation">移动至指定位置button>
<button ontap="movetonowlocation">移动至当前位置view>
page({
data: {
mapctx: null
},
onready() {
this.data.mapctx = my.createmapcontext('map');
},
movetolocation() {
this.data.mapctx.movetolocation({
latitude: 39.9,
longitude: 116.39,
success: res => {
console.log(res);
},
fail: error => {
console.log(error)
}
});
},
movetonowlocation() {
this.data.mapctx.movetolocation({
success: res => {
console.log(res);
},
fail: error => {
console.log(error)
}
});
},
});
-
tip在客户端 10.3.80 版本之前,mapcontext.movetolocation 的调用会导致地图被设置为默认缩放级别(16)。
-
bug在 ios 10.3.60 版本之前,未填写入参经纬度且未在 map 组件中添加 show-location 时不会报错,会执行 success 回调并返回
success: true
。请在入参中指定经纬度,或在 map 组件中添加 show-location。