更新记录
1.0.0(2025-06-28)
+新版发布
平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | - | - | 5.0 | 12 | × |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | - | × | × | × | × |
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | 5.0 | 12 | × | × |
高德定位、连续定位、后台定位、保活定位
开发文档
UTS 语法 UTS API插件 UTS uni-app兼容模式组件 UTS 标准模式组件 Hello UTS
特别提醒
- 购买本插件前,请先试用、并充分自测后再购买,购买后无法退款;
- 如有使用上的疑问、bug,可以***联系作者;
- 结合文档和示例代码集成使用;
- 试用必须先打基座、试用必须先打基座、试用必须先打基座重要事情说三遍;
- 本插件支持/-x项目,支持vue2/vue3,支持iOS、Android
- Android手机型号太多,各品牌对手机的限制不尽相同,需要保活而进行的设置也不一样。随着Android系统的更新迭代,保活的难度也在不断加大。最有效的保活方式还是联系厂家添加白名单以实现进程保活。
- ***使用本插件保活、后台定位功能iOS需在manifest.json/其他设置中后台运行能力配置location
插件功能介绍
- 定位、连续定位、后台定位(Android需要使用保活定位)
- 保活定位
Android后台采集或保活设置
-
通知管理允许通知,允许自启动;
-
耗电保护允许后台运行;
-
电池设置中关闭智能耗电保护、省电模式、应用速冻等。
集成插件步骤
- 点击试用/购买选择需要集成项目
- 调用插件在需要使用的地方导入 import * as GDLocation from '../../uni_modules/ly-amaplocation' 可参考下面的实例代码
- Android配置高德key,事先先申请的key,替换:uni_modules/ly-amaplocation/utssdk/app-android/AndroidManifest.xml文件下<meta-data android:name="com.amap.api.v2.apikey" android:value="自己的key" />。
- iOS配置高德key替换:uni_modules/ly-amaplocation/utssdk/app-ios/info.plist中GDAPIKey
- 配置完打自定义基座测试
api说明
单次定位:GDLocation.onceLocation(options:LocationOptions,locationHandler(location=>{}))
GDLocation.onceLocation({
locationMode: 'HundredMeters',
reGeocode: true,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
连续定位:GDLocation.updateLocation(options:LocationOptions,locationHandler(location=>{}))
GDLocation.updateLocation({
locationMode: 'HundredMeters',
anLocationMode: "Hight_Accuracy",
reGeocode: true,
isAllow: true,
locationInterval: 10000,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
///停止连续定位
GDLocation.stopUpdateLocation()
保活定位:GDLocation.keepLive(options:LocationOptions,locationHandler(location=>{}))
GDLocation.keepLive({
locationMode: 'HundredMeters',
reGeocode: true,
isAllow: true,
locationInterval: 5000,
anLocationMode: "Battery_Saving",
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
///停止保活定位
GDLocation.stopKeepLive();
打开App对应设置页面
GDLocation.openAppSettings()
参数说明:LocationOptions 定位参数
参数 | 类型 | 说明 |
---|---|---|
locationMode | String | iOS端定位精度'BestForNavigation' 、 'AccuracyBest' 、 'NearestTenMeters' 、 'HundredMeters'、'Kilometer' |
anLocationMode | String | android端定位精度 Hight_Accuracy 、 Battery_Saving 、Device_Sensors |
reGeocode | bool | 是否需要地址默认true |
locationInterval | int | 连续定位间隔默认10*1000 |
isAllow | bool | 是否后台定位仅连续定位有效,保活定位默认开启后台定位 |
notificationTitle | string | 仅Android有效设置后台定位通知标题 |
notificationContentText | string | 仅Android有效设置后台定位通知内容 |
locationHandler | function | 定位回调 |
locationMode:补充说明,iOS端定位精度设置BestForNavigation:导航级精度,±1米内
参数 | 说明 |
---|---|
BestForNavigation | 导航级精度,±1米内 |
AccuracyBest | 设备支持的最佳精度,±10米内 |
NearestTenMeters | ±10米 默认 |
HundredMeters | ±100米 |
Kilometer | ±1公里 |
anLocationMode:Android端定位精度
参数 | 说明 |
---|---|
Hight_Accuracy | 高精度模式 |
Battery_Saving | 低功耗模式 |
Device_Sensors | 仅设备模式,不支持室内环境的定位 |
定位回调说明
定位回调返回的数据类型location:LocationInfo。
字段 | 类型 | 说明 |
---|---|---|
code | int | 状态码 200成功 |
mes | string | 定位说明 |
latitude | number | 纬度 |
longitude | number | 经度 |
speed | number | 速度 |
altitude | number | 海拔 |
address | AddressInfo | 地址信息,详情见下表 |
AddressInfo说明:
字段 | 类型 | 说明 |
---|---|---|
formattedAddress | string | 格式化地址 |
country | string | 国家 |
province | string | 省/直辖市 |
city | string | 市 |
district | string | 区 |
citycode | string | 城市编码 |
adcode | string | 区域编码 |
street | string | 街道名称 |
number | string | 门牌号 |
poiName | string | 兴趣点名称 |
aoiName | string | 所属兴趣点名称 |
***完整示例
<template>
<view>
<view class="text-area">
<text class="title" @click="oneceLocationAction">单次定位</text>
<text class="title" @click="updateLocation">连续定位</text>
<text class="title" @click="keepLive">保活定位</text>
<text class="title" @click="stopUpdateLocation">取消连续定位</text>
<text class="title" @click="stopKeepLive">取消保活定位</text>
<text class="title" @click="openAppSettings">打开设置页面</text>
</view>
</view>
</template>
<script>
import * as GDLocation from '../../uni_modules/ly-amaplocation'
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
oneceLocationAction() {
GDLocation.onceLocation({
locationMode: 'HundredMeters',
reGeocode: true,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
})
},
//连续定位
updateLocation() {
GDLocation.updateLocation({
locationMode: 'HundredMeters',
anLocationMode: "Hight_Accuracy",
reGeocode: true,
isAllow: true,
locationInterval: 10000,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
})
},
//后台保活定位
keepLive() {
GDLocation.keepLive({
locationMode: 'HundredMeters',
reGeocode: true,
isAllow: true,
locationInterval: 5000,
anLocationMode: "Battery_Saving",
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
})
},
//取消连续定位
stopUpdateLocation() {
GDLocation.stopUpdateLocation()
},
//停止保活
stopKeepLive() {
GDLocation.stopKeepLive()
},
//跳设置页面
openAppSettings() {
GDLocation.openAppSettings()
},
}
}
</script>
<style>
.title {
font-size: 18px;
color: #8f8f94;
text-align: center;
margin-top: 45rpx;
}
.text-area {
display: flex;
flex-direction: column;
align-items: center;
width: 750rpx;
}
</style>
***-x完整示例
<template>
<view>
<view class="text-area">
<text class="title" @click="oneceLocationAction">单次定位</text>
<text class="title" @click="updateLocation">连续定位</text>
<text class="title" @click="keepLive">保活定位</text>
<text class="title" @click="stopUpdateLocation">取消连续定位</text>
<text class="title" @click="stopKeepLive">取消保活定位</text>
<text class="title" @click="openAppSettings">打开设置页面</text>
</view>
</view>
</template>
<script>
import * as GDLocation from '../../uni_modules/ly-amaplocation'
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
oneceLocationAction() {
GDLocation.onceLocation({
locationMode: 'HundredMeters',
reGeocode: true,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
},
//连续定位
updateLocation() {
GDLocation.updateLocation({
locationMode: 'HundredMeters',
anLocationMode: "Hight_Accuracy",
reGeocode: true,
isAllow: true,
locationInterval: 10000,
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
},
//后台保活定位
keepLive() {
GDLocation.keepLive({
locationMode: 'HundredMeters',
reGeocode: true,
isAllow: true,
locationInterval: 5000,
anLocationMode: "Battery_Saving",
locationHandler: (location) => {
if (location.code == 200) {
console.log(location)
}
}
} as GDLocation.LocationOptions)
},
//取消连续定位
stopUpdateLocation() {
GDLocation.stopUpdateLocation()
},
//停止保活
stopKeepLive() {
GDLocation.stopKeepLive()
},
//跳设置页面
openAppSettings() {
GDLocation.openAppSettings()
},
}
}
</script>
<style>
.title {
font-size: 18px;
color: #8f8f94;
text-align: center;
margin-top: 45rpx;
}
.text-area {
display: flex;
flex-direction: column;
align-items: center;
width: 750rpx;
}
</style>