swan.openLocation
解释:使用宿主 App 内置地图查看位置。
方法参数
Object object
object 参数说明
示例
扫码体验
请使用百度APP扫码
图片示例
代码示例1 - 自定义位置信息 :
在开发者工具中预览效果 -
Page({ data: { locationInfo: { latitude: 40.04, longitude: 116.27, scale: 18, name: '百度科技园', address: '北京市海淀区西北旺东路10号院' } }, openLocation () { let locationInfo = this.data.locationInfo; swan.openLocation({ latitude: locationInfo.latitude, longitude: locationInfo.longitude, scale: locationInfo.scale, name: locationInfo.name, address: locationInfo.address, success: res => { console.log('openLocation success', res); }, fail : function (err) { console.log('openLocation fail', err); } }); }})
代码示例2 - 地图默认位置信息 :
在开发者工具中预览效果 -
Page({ data: { locationInfo: { latitude: 40.04, longitude: 116.27, scale: 18 } }, openLocation () { let locationInfo = this.data.locationInfo; swan.openLocation({ latitude: locationInfo.latitude, longitude: locationInfo.longitude, scale: locationInfo.scale, success: res => { console.log('openLocation success', res); }, fail : function (err) { console.log('openLocation fail', err); } }); }})
