swan.chooseLocation
解释: 打开地图选择位置。需要用户授权 scope.userLocation。使用该 API 需通过获取用户权限设置申请授权后方可对用户发起授权申请,可在需授权接口列表中查看相关错误码信息。
方法参数
Object object
object参数说明
success 返回参数说明
示例
在开发者工具中预览效果
扫码体验
请使用百度APP扫码
图片示例
代码示例
-
Page({ chooseLocation() { swan.authorize({ scope: 'scope.userLocation', success: res => { console.log(res); }, fail: function () { swan.openSetting({}) } }); let that = this; swan.chooseLocation({ success: res => { console.log('success', res); let longitude = 'E:' + that.formatLocation(res.longitude) + '′'; let latitude = 'N:' + that.formatLocation(res.latitude) + '′'; that.setData({ 'name': res.name, 'address': res.address, 'longitude': longitude, 'latitude': latitude }); }, fail: err => { console.log('错误码:' + err.errCode); console.log('错误信息:' + err.errMsg); } }); }, formatLocation(data) { return data.toFixed(2).replace('.', '°'); }})
