更新记录
1.0.0(2026-07-19)
初始化
平台兼容性
uni-app(3.7.11)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
- |
- |
√ |
√ |
√ |
√ |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.45)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
√ |
√ |
√ |
- |
xtf-baiduselectpos
百度地图选点插件,提供原生位置选择界面,支持 Android、iOS、Harmony。
功能说明
- 打开地图选点页,返回用户最终选择的位置
- 支持默认中心点、默认关键词、默认城市
- 支持返回
BD09LL 或 GPS(WGS84) 坐标
- 支持顶部文案、搜索文案、按钮颜色、列表颜色等 UI 自定义
支持平台
| 平台 |
支持情况 |
| Android |
支持 |
| iOS |
支持 |
| Harmony |
支持 |
使用前说明
- 需要分别配置百度地图平台 Key:
android_key、ios_key、harmony_key。
- iOS 端依赖原生 SDK,必须使用自定义基座运行,不能只用标准基座验证。
- 地图内部搜索与展示使用百度坐标系
BD09LL,仅最终成功回调可按 returnCoordinateType 转成 GPS。
导出方法
openLocationPicker(options)
作用:打开百度地图位置选择页面,用户确认后返回所选地点信息。
uni-app x 导入方式
import { openLocationPicker } from '@/uni_modules/xtf-baiduselectpos'
uni-app 导入方式
import { openLocationPicker } from '@/uni_modules/xtf-baiduselectpos'
参数 OpenLocationPickerOptions
| 参数 |
类型 |
是否必填 |
作用 |
android_key |
string |
Android 必填 |
百度地图 Android Key |
ios_key |
string |
iOS 必填 |
百度地图 iOS Key |
iosKey |
string |
否 |
ios_key 的兼容写法 |
harmony_key |
string |
Harmony 必填 |
百度地图 Harmony Key |
latitude |
number |
否 |
默认中心点纬度 |
longitude |
number |
否 |
默认中心点经度 |
returnCoordinateType |
'BD09LL' \| 'GPS' |
否 |
成功回调返回的坐标系,默认 BD09LL |
keyword |
string |
否 |
默认搜索关键词,进入选点页后会按该关键词搜索 |
city |
string |
否 |
默认搜索城市,关键词搜索优先使用该城市 |
showLogo |
boolean |
否 |
是否显示地图 Logo |
showScaleBar |
boolean |
否 |
是否显示比例尺 |
showGpsLocation |
boolean |
否 |
是否显示当前定位蓝点 |
showLocateButton |
boolean |
否 |
是否显示定位按钮 |
locateIconPath |
string |
否 |
自定义定位按钮图标路径 |
centerIconPath |
string |
否 |
自定义中心点图标路径 |
zoom |
number |
否 |
地图默认缩放级别 |
showTopBar |
boolean |
否 |
是否显示顶部栏 |
showCancelButton |
boolean |
否 |
是否显示顶部取消按钮 |
showConfirmButton |
boolean |
否 |
是否显示顶部确认按钮 |
cancelText |
string |
否 |
取消按钮文案 |
confirmText |
string |
否 |
确认按钮文案 |
searchHintText |
string |
否 |
搜索框占位文案 |
searchCancelText |
string |
否 |
搜索态取消按钮文案 |
nearbyTipText |
string |
否 |
附近地点模式提示文案 |
searchModeTipText |
string |
否 |
搜索结果模式提示文案 |
searchingText |
string |
否 |
搜索中提示文案 |
draggingText |
string |
否 |
拖动地图时提示文案 |
locatingText |
string |
否 |
定位中提示文案 |
confirmButtonColor |
string |
否 |
确认按钮背景色 |
confirmButtonDisabledColor |
string |
否 |
确认按钮禁用态背景色 |
confirmTextColor |
string |
否 |
确认按钮文字颜色 |
cancelTextColor |
string |
否 |
取消按钮文字颜色 |
searchCancelTextColor |
string |
否 |
搜索取消按钮文字颜色 |
topBarTextColor |
string |
否 |
顶部栏主要文字颜色 |
bottomSheetColor |
string |
否 |
底部面板背景色 |
searchBoxColor |
string |
否 |
搜索框背景色 |
searchTextColor |
string |
否 |
搜索输入文字颜色 |
searchHintColor |
string |
否 |
搜索占位文字颜色 |
poiTitleColor |
string |
否 |
POI 标题颜色 |
poiAddressColor |
string |
否 |
POI 地址颜色 |
poiSelectedTitleColor |
string |
否 |
已选中 POI 标题颜色 |
poiSelectedAddressColor |
string |
否 |
已选中 POI 地址颜色 |
poiCheckColor |
string |
否 |
已选中标记颜色 |
success |
(res) => void |
否 |
选点成功后的回调 |
fail |
(err) => void |
否 |
打开失败、鉴权失败、权限拒绝或用户取消时的回调 |
complete |
(res) => void |
否 |
接口结束后的回调,成功和失败都会执行 |
success(res) 回调作用
作用:在用户确认位置后返回最终选中的地点信息。
| 字段 |
类型 |
作用 |
latitude |
number |
选中点纬度 |
longitude |
number |
选中点经度 |
name |
string |
地点名称 |
address |
string |
地点地址 |
city |
string |
城市名 |
district |
string |
区县名 |
adCode |
string |
行政区编码 |
fail(err) 回调作用
作用:在打开页面失败、缺少 Key、地图 SDK 初始化失败等场景下返回错误信息。
| 字段 |
类型 |
作用 |
errCode |
9015001 \| 9015002 \| 9015003 \| 9015004 \| 9015005 |
错误码 |
errMsg |
string |
错误描述 |
常见错误码说明:
| 错误码 |
说明 |
9015001 |
当前无法获取页面 Activity |
9015002 |
用户取消了位置选择 |
9015003 |
当前平台暂不支持百度位置选择 |
9015004 |
定位权限未授予 |
9015005 |
百度地图配置缺失或初始化失败 |
complete(res) 回调作用
作用:无论成功还是失败都会执行,适合做统一收尾处理,比如关闭 loading、记录日志。
使用示例
uni-app x
import { openLocationPicker, type OpenLocationPickerOptions } from '@/uni_modules/xtf-baiduselectpos'
const options: OpenLocationPickerOptions = {
android_key: 'your-android-key',
ios_key: 'your-ios-key',
harmony_key: 'your-harmony-key',
keyword: '写字楼',
city: '北京',
returnCoordinateType: 'GPS',
confirmText: '确定',
success(res) {
console.log('select success', res)
},
fail(err) {
console.log('select fail', err)
},
complete(res) {
console.log('select complete', res)
}
}
openLocationPicker(options)
uni-app
import { openLocationPicker } from '@/uni_modules/xtf-baiduselectpos'
openLocationPicker({
android_key: 'your-android-key',
ios_key: 'your-ios-key',
harmony_key: 'your-harmony-key',
keyword: '写字楼',
city: '北京',
returnCoordinateType: 'GPS',
confirmText: '确定',
success(res) {
console.log('select success', res)
},
fail(err) {
console.log('select fail', err)
},
complete(res) {
console.log('select complete', res)
}
})
坐标说明
BD09LL:百度坐标系,插件默认返回值
GPS:WGS84 坐标,适合与通用 GPS 坐标系统对接
适用场景
- 地址选择
- 门店选址
- 上门服务定位
- 表单中补充经纬度和详细地址