更新记录
1.0.0(2025-05-30)
- 新版发布
平台兼容性
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 | × | × |
ly-native-location
特别提醒
- 购买本插件前,请先试用、请先试用、请先试用,并充分自测确认满足需求之后再行购买。虚拟物品一旦购买之后无法退款;
- 如有使用上的疑问、bug,可以进交流群联系作者;
- 请在合法范围内使用,若使用本插件做非法开发,本方概不负责;
- 结合文档和示例代码集成使用;
- 试用必须先打基座、试用必须先打基座、试用必须先打基座;
插件功能介绍 (支持uni-app/uni-app-x)
- 定位、连续定位、后台定位(Android需要使用保活定位)
- 保活
Android后台采集或保活设置
-
通知管理允许通知,允许自启动;
-
耗电保护允许后台运行;
-
电池设置中关闭智能耗电保护、省电模式、应用速冻等。
注意事项:
- 本插件使用需要打自定义基座调试、试用。
- Android手机型号太多,各品牌对手机的限制不尽相同,需要保活而进行的设置也不一样。随着Android系统的更新迭代,保活的难度也在不断加大。最有效的保活方式还是联系厂家添加白名单以实现进程保活。
-
定位返回WGS84坐标.(后续会添加坐标系转换)
定位
定位需要注意的地方:
- iOS后台定位定位间隔不能设置太大
- Android后台定位,请使用保活定位。
uniapp 示例代码
<template>
<view class="content">
<view class="header">
<view class="btn" @click="onceLocationAction()">单次定位</view>
<view class="btn" @click="startUpdatingLocationAction()">连续定位</view>
<view class="btn" @click="keepAliveAction()">保活定位</view>
</view>
<view class="header">
<view class="btn" @click="stopUpdatingLocationAction()">停止连续定位</view>
<view class="btn" @click="nonKeepAliveAction()">停止保活</view>
</view>
</view>
</template>
<script>
import * as NativeLocation from "@/uni_modules/ly-native-location"
export default {
data() {
return {
locationCount: 0
}
},
onLoad() {
NativeLocation.configureBasicConfiguration({
onceLocationTimeout: 5000,//单次定位超时时间,可选参数仅Android有效
locationInterval: 4000,//连续定位、保活定位间隔 可选参数默认10秒
notificationTitle: "App后台定位中",//保活前台通知栏 标题、仅Android有效
notificationContentText: "正在后台定位"//保活前台通知栏 内容、仅Android有效
})
},
methods: {
onceLocationAction() {
NativeLocation.onceLocation({
locationResultBackcall: (res) => {
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位成功--精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
} else {
uni.showToast({
icon: "none",
title: res.mes
})
}
}
});
},
//连续定位
startUpdatingLocationAction() {
NativeLocation.startUpdatingLocation({
enableBackgroundLocation: false,
locationResultBackcall: (res) => {
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位次数:${this.locationCount}精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
} else {
uni.showToast({
icon: "none",
title: res.mes
})
}
}
})
},
//停止连续定位
stopUpdatingLocationAction() {
this.locationCount = 0
NativeLocation.stopUpdatingLocation()
},
//保活
keepAliveAction() {
NativeLocation.keepLiveLocation({
locationResultBackcall: (res) => {
console.log('1111111111111')
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位次数:${this.locationCount}精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
} else {
uni.showToast({
icon: "none",
title: res.mes
})
}
}
})
},
//停止保活
nonKeepAliveAction() {
this.locationCount = 0
NativeLocation.offKeepLiveLocation()
}
}
}
</script>
<style>
.content {
width: 750rpx;
display: flex;
height: 100%;
flex-direction: column;
}
.header {
width: 750rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 0 10rpx;
margin-top: 40rpx;
box-sizing: border-box;
}
.btn {
display: flex;
height: 80rpx;
flex: 1;
align-items: center;
justify-content: center;
background-color: cadetblue;
color: white;
margin-right: 10rpx;
font-size: 28rpx;
}
</style>
uni-app-x示例代码
<template>
<view class="content">
<view class="header">
<view class="btn" @click="onceLocationAction()">单次定位</view>
<view class="btn" @click="startUpdatingLocationAction()">连续定位</view>
<view class="btn" @click="keepAliveAction()">保活定位</view>
</view>
<view class="header">
<view class="btn" @click="stopUpdatingLocationAction()">停止连续定位</view>
<view class="btn" @click="nonKeepAliveAction()">停止保活</view>
</view>
</view>
</template>
<script>
import * as NativeLocation from "@/uni_modules/ly-native-location"
export default {
data() {
return {
locationCount: 0
}
},
onLoad() {
NativeLocation.configureBasicConfiguration({
onceLocationTimeout: 5000,//单次定位超时时间,可选参数仅Android有效
locationInterval: 4000,//连续定位、保活定位间隔 可选参数默认10秒
notificationTitle: "App后台定位中",//保活前台通知栏 标题、仅Android有效
notificationContentText: "正在后台定位"//保活前台通知栏 内容、仅Android有效
})
},
methods: {
onceLocationAction() {
NativeLocation.onceLocation({
locationResultBackcall: (res) => {
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位成功:${this.locationCount}---精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
} else {
uni.showToast({
icon: "none",
title: `${res.mes}`
})
}
}
});
},
//连续定位
startUpdatingLocationAction() {
NativeLocation.startUpdatingLocation({
enableBackgroundLocation: false,
locationResultBackcall: (res) => {
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位次数:${this.locationCount}---精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
}
}
} as NativeLocation.UpdatingLocationOptions)
},
//停止连续定位
stopUpdatingLocationAction() {
this.locationCount = 0
NativeLocation.stopUpdatingLocation()
},
//保活
keepAliveAction() {
NativeLocation.keepLiveLocation({
locationResultBackcall: (res) => {
console.log('1111111111111')
if (res.code == 200) {
this.locationCount++;
uni.showToast({
icon: 'none',
title: `定位次数:${this.locationCount}---精度:${res.location?.longitude}----纬度:${res.location?.latitude}`
})
}
}
})
},
//停止保活
nonKeepAliveAction() {
this.locationCount = 0
NativeLocation.offKeepLiveLocation()
}
}
}
</script>
<style>
.content {
width: 750rpx;
display: flex;
height: 100%;
flex-direction: column;
}
.header {
width: 750rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 0 10rpx;
margin-top: 40rpx;
box-sizing: border-box;
}
.btn {
display: flex;
height: 80rpx;
flex: 1;
align-items: center;
justify-content: center;
background-color: cadetblue;
color: white;
margin-right: 10rpx;
font-size: 28rpx;
}
</style>