更新记录
1.0.0(2025-04-21)
新版发布
平台兼容性
Vue2 | Vue3 |
---|---|
√ | √ |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
HBuilderX 3.6.8,Android:5.1,iOS:11,HarmonyNext:不支持 | × | × | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 | 鸿蒙元服务 |
---|---|---|---|---|
× | × | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
特别提醒
- 购买本插件前,请先试用、请先试用、请先试用,并充分自测确认满足需求之后再行购买。虚拟物品一旦购买之后无法退款;
- 如有使用上的疑问、bug,可以进交流群联系作者;
- 作者可承接各种插件定制;
- 请在合法范围内使用,若使用本插件做非法开发,本方概不负责;
- 结合文档和示例代码集成使用;
- 试用必须先打自定义基座;
插件功能介绍 (支持uni-app/uni-app-x)
- 定位、连续定位、后台定位(Android需要使用保活定位)
- 坐标转换
- 保活
Android后台采集或保活设置
-
通知管理允许通知,允许自启动;
-
耗电保护允许后台运行;
-
电池设置中关闭智能耗电保护、省电模式、应用速冻等。
注意事项:
- 本插件使用需要打自定义基座调试、试用。
- 打基座、打包前要先配置百度定位key iOS:uni_modules->yt-uts-bdlocation->utssdk->app-ios->info.plist文件中 Android:uni_modules->yt-uts-bdlocation->utssdk->app-android->AndroidManifest.xml文件中;
- Android手机型号太多,各品牌对手机的限制不尽相同,需要保活而进行的设置也不一样。随着Android系统的更新迭代,保活的难度也在不断加大。最有效的保活方式还是联系厂家添加白名单以实现进程保活。
- iOS保活定位调用连续定位设置isAllow=true,andoid保活定位调用keepAlive方法,更多参数说明可进入uni_modules->yt-uts-bdlocation->interface.uts文件查看,里面有各个参数的详细说明。
定位
定位需要注意的地方:
- iOS后台定位定位间隔不能设置太大,应小于12秒
- 3.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 class="header" style="margin-top: 30rpx;">
<view class="btn" @click="gcj02ToBd09Action()">
gcj02ToBd09
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="bd09ToGcj02()">
bd09ToGcj02
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="bd09ToWgs84()">
bd09ToWgs84
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="gcj02ToWgs84()">
gcj02ToWgs84
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="wgs84ToBd09()">
wgs84ToBd09
</view>
</view>
</view>
</template>
<script>
import {
onceLocation,
startUpdatingLocation,
stopUpdatingLocation,
keepAlive,
nonKeepAlive,
LocationOptions,
KeepLiveOptions,
gcj02ToBd09,
bd09ToGcj02,
bd09ToWgs84,
gcj02ToWgs84,
wgs84ToBd09
} from "@/uni_modules/yt-uts-bdlocation"
export default {
data() {
return {
locationCount: 0,
lat: 0.00,
lng: 0.00
}
},
methods: {
onceLocationAction() {
onceLocation({
locationMode: 'Hight_Accuracy',
locationTimeout: 10000,
coorType: 'bd09ll',
reGeocode: true,
openGps: true,
resultBackcall: (res) => {
if (res.code == 200) {
let lat = res.lat ?? 0.0;
let lng = res.lng ?? 0.0;
this.lat = lat;
this.lng = lng;
uni.showToast({
title: `定位成功精度:${lng}---纬度:${lat}`,
icon: 'none'
})
}
}
});
},
//连续定位
startUpdatingLocationAction() {
startUpdatingLocation({
locationMode: 'Hight_Accuracy',
locationTimeout: 10000,
coorType: 'gcj02',
reGeocode: true,
openGps: true,
scanSpan: 10000,
isAllow: true,
resultBackcall: (res) => {
this.locationCount++;
if (res.code == 200) {
console.log(res.address ?? "");
let lat = res.lat ?? 0.0;
let lng = res.lng ?? 0.0;
this.lat = lat;
this.lng = lng;
uni.showToast({
title: `定位成功次数:${this.locationCount}精度:${lng}-纬度:${lat}`,
icon: 'none'
})
};
}
});
},
//停止连续定位
stopUpdatingLocationAction() {
stopUpdatingLocation()
},
//保活
keepAliveAction() {
keepAlive({
openGps: true,
scanSpan: 10000,
resultBackcall: (res) => {
console.log(res);
this.locationCount++;
uni.showToast({
icon: 'none',
title: `第${this.locationCount}次定位精度:${res.lng}---纬度:${res.lat}`
})
}
})
},
//停止保活
nonKeepAliveAction() {
nonKeepAlive()
},
//gcj02ToBd09
gcj02ToBd09Action() {
console.log('进来了')
// if (this.lat == 0) return;
console.log(gcj02ToBd09(this.lat, this.lng))
},
//bd09ToGcj02
bd09ToGcj02() {
if (this.lat == 0) return;
console.log(bd09ToGcj02(this.lat, this.lng))
},
//bd09ToWgs84
bd09ToWgs84() {
if (this.lat == 0) return;
console.log(bd09ToWgs84(this.lat, this.lng))
},
//gcj02ToWgs84
gcj02ToWgs84() {
if (this.lat == 0) return;
console.log(gcj02ToWgs84(this.lat, this.lng))
},
//wgs84ToBd09
wgs84ToBd09() {
if (this.lat == 0) return;
console.log(wgs84ToBd09(this.lat, this.lng))
}
}
}
</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 class="header" style="margin-top: 30rpx;">
<view class="btn" @click="gcj02ToBd09()">
gcj02ToBd09
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="bd09ToGcj02()">
bd09ToGcj02
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="bd09ToWgs84()">
bd09ToWgs84
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="gcj02ToWgs84()">
gcj02ToWgs84
</view>
</view>
<view class="header" style="margin-top: 30rpx;">
<view class="btn" @click="wgs84ToBd09()">
wgs84ToBd09
</view>
</view>
</view>
</template>
<script>
import {
onceLocation, startUpdatingLocation, stopUpdatingLocation, keepAlive, nonKeepAlive, LocationOptions, KeepLiveOptions, gcj02ToBd09, bd09ToGcj02, bd09ToWgs84, gcj02ToWgs84, wgs84ToBd09
} from "@/uni_modules/yt-uts-bdlocation"
export default {
data() {
return {
locationCount: 0,
lat: 0.00,
lng: 0.00
}
},
methods: {
onceLocationAction() {
onceLocation({
locationMode: 'Hight_Accuracy',
locationTimeout: 10000,
coorType: 'bd09ll',
reGeocode: true,
openGps: true,
resultBackcall: (res) => {
if (res.code == 200) {
let lat = res.lat ?? 0.0;
let lng = res.lng ?? 0.0;
this.lat = lat;
this.lng = lng;
console.log(`精度:${lng} 纬度:${lat}`)
uni.showToast({
title: `定位成功精度:${lng}---纬度:${lat}`,
icon: 'none'
})
}
}
} as LocationOptions);
},
//连续定位
startUpdatingLocationAction() {
startUpdatingLocation({
locationMode: 'Hight_Accuracy',
locationTimeout: 10000,
coorType: 'gcj02',
reGeocode: true,
openGps: true,
scanSpan: 10000,
isAllow: true,
resultBackcall: (res) => {
this.locationCount++;
if (res.code == 200) {
console.log(res.address ?? "");
let lat = res.lat ?? 0.0;
let lng = res.lng ?? 0.0;
uni.showToast({
title: `定位成功次数:${this.locationCount}精度:${lng}-纬度:${lat}`,
icon: 'none'
})
};
}
} as LocationOptions);
},
//停止连续定位
stopUpdatingLocationAction() {
stopUpdatingLocation()
},
//保活
keepAliveAction() {
keepAlive({
openGps: true,
scanSpan: 10000,
resultBackcall: (res) => {
console.log(res);
this.locationCount++;
uni.showToast({
icon: 'none',
title: `第${this.locationCount}次定位精度:${res.lng}---纬度:${res.lat}`
})
}
} as KeepLiveOptions)
},
//停止保活
nonKeepAliveAction() {
nonKeepAlive()
},
//gcj02ToBd09
gcj02ToBd09() {
// if (this.lat == 0) return;
// gcj02ToBd09(this.lat, this.lng).get('latitude')
let result : UTSJSONObject = gcj02ToBd09(this.lat, this.lng);
console.log(JSON.stringify(result))
},
//bd09ToGcj02
bd09ToGcj02() {
if (this.lat == 0) return;
console.log(bd09ToGcj02(this.lat, this.lng))
},
//bd09ToWgs84
bd09ToWgs84() {
if (this.lat == 0) return;
console.log(bd09ToWgs84(this.lat, this.lng))
},
//gcj02ToWgs84
gcj02ToWgs84() {
if (this.lat == 0) return;
console.log(gcj02ToWgs84(this.lat, this.lng))
},
//wgs84ToBd09
wgs84ToBd09() {
if (this.lat == 0) return;
console.log(wgs84ToBd09(this.lat, this.lng))
}
}
}
</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>