uniapp 实时定位(系统、后台运行、支持息屏)插件 Ba-Location

简介(下载地址

Ba-Location 是一款系统GPS实时定位插件,可后台运行,可以息屏运行,可在内网使用。

本插件自带一种保活技术,如果需要进一步保活,请使用 Ba-KeepAlive

注意:GPS定位不支持室内定位,测试建议在室外或窗口。

  • 支持设置位置信息更新周期,单位秒
  • 支持设置位置变化最小距离:当位置距离变化超过此值时,将更新位置信息

截图展示

在这里插入图片描述

使用方法

script 中引入组件

	const location = uni.requireNativePlugin('Ba-Location')

script 中调用(示例参考,可根据自己业务和调用方法自行修改)

	const location = uni.requireNativePlugin('Ba-Location')
	export default {
    
    
		data() {
    
    
			return {
    
    
				msgList: [],
				minTimeMs: 30,
				minDistanceM: 1
			}
		},
		onLoad() {
    
    
			this.subLocation();
			//this.subGpsStatus();
			//this.subLocationStatus();
		},
		methods: {
    
    
			startL() {
    
     //开启定位
				location.start(
					res => {
    
    
						console.log(res);
						uni.showToast({
    
    
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					}, {
    
    
						minTimeMs: this.minTimeMs,
						minDistanceM: this.minDistanceM
					});
			},
			stopL() {
    
     //关闭定位
				location.stop(res => {
    
    
					console.log(res);
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			isLocationService() {
    
     //定位服务是否开启
				location.isLocationService(
					res => {
    
    
						console.log(res);
						if (res.data) {
    
    
							this.msgList.unshift(JSON.stringify(res.data))
							this.msgList.unshift(dateUtil.now())
						}
						uni.showToast({
    
    
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					});
			},
			isLocationEnable() {
    
     //定位开关是否打开
				location.isLocationEnable(
					res => {
    
    
						console.log(res);
						if (res.data) {
    
    
							this.msgList.unshift(JSON.stringify(res.data))
							this.msgList.unshift(dateUtil.now())
						}
						uni.showToast({
    
    
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					});
			},
			goSetting() {
    
     //跳转到定位服务设置界面
				location.goSetting(
					res => {
    
    
						console.log(res);
						uni.showToast({
    
    
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					});
			},
			subLocation() {
    
     //订阅定位信息
				location.subLocation(res => {
    
    
					console.log(res);
					if (res.data) {
    
    
						this.msgList.unshift(JSON.stringify(res.data))
						this.msgList.unshift(dateUtil.now())
					}
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			subLocationStatus() {
    
     //订阅定位状态变化
				location.subLocationStatus(res => {
    
    
					console.log(res);
					if (res.data) {
    
    
						this.msgList.unshift(JSON.stringify(res.data))
						this.msgList.unshift(dateUtil.now())
					}
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			subGpsStatus() {
    
     //订阅 gps和 搜星变化
				location.subGpsStatus(res => {
    
    
					console.log(res);
					if (res.data) {
    
    
						this.msgList.unshift(JSON.stringify(res.data))
						this.msgList.unshift(dateUtil.now())
					}
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
		}
	}	

api 列表

方法名 说明
start 开启定位服务
stop 停止定位服务
subLocation 订阅定位信息
isLocationService 定位服务是否开启
isLocationEnable 定位开关是否打开
goSetting 跳转到定位服务设置界面
subLocationStatus 订阅定位状态变化
subGpsStatus 订阅 gps状态(如搜星)

start 方法参数

开启定位服务

属性名 类型 必填 默认值 说明
minTimeMs Number false 30 位置信息更新周期,单位秒
minDistanceM Number false 1 位置变化最小距离,单位M:当位置距离变化超过此值时,将更新位置信息
altitudeRequired Boolean false false 是否需要海拔信息
bearingRequired Boolean false false 是否需要方位信息
speedRequired Boolean false false 是否需要速度
isNotification Boolean false true 是否开启通知,建议开启,有一定保活作用,默认 true

subLocation 接收参数

订阅定位信息,res.data

属性名 类型 说明
longitude Number 经度
latitude Number 纬度
time Number 时间
speed Number 速度
altitude Number 海拔,单位 m
bearing Number 方位
accuracy Number 位置的精确度

系列插件

图片选择插件 Ba-MediaPicker文档

图片编辑插件 Ba-ImageEditor文档

文件选择插件 Ba-FilePicker文档

应用消息通知插件(多种样式,新增支持常驻通知模式) Ba-Notify文档

应用未读角标插件 Ba-Shortcut-Badge文档

应用开机自启插件 Ba-Autoboot文档

扫码原生插件(毫秒级、支持多码)Ba-Scanner-G文档

扫码原生插件 - 新(可任意自定义界面版本;支持连续扫码;支持设置扫码格式)Ba-Scanner文档

动态修改状态栏、导航栏背景色、字体颜色插件 Ba-AppBar文档

原生sqlite本地数据库管理 Ba-Sqlite文档

安卓保活插件(采用多种主流技术) Ba-KeepAlive文档

安卓快捷方式(桌面长按app图标) Ba-Shortcut文档

自定义图片水印(任意位置) Ba-Watermark文档

最接近微信的图片压缩插件 Ba-ImageCompressor文档

视频压缩、视频剪辑插件 Ba-VideoCompressor文档

动态切换应用图标、名称(如新年、国庆等) Ba-ChangeIcon文档

原生Toast弹窗提示(穿透所有界面、穿透原生;自定义颜色、图标 ) Ba-Toast文档

图片涂鸦、画笔 Ba-ImagePaint文档

pdf阅读(手势缩放、显示页数) Ba-Pdf文档

声音提示、震动提示、语音播报 Ba-Beep文档

websocket原生服务(自动重连、心跳检测) Ba-Websocket文档

短信监听(验证码) Ba-Sms文档

智能安装(自动升级) Ba-SmartUpgrade文档

监听系统广播、自定义广播 Ba-Broadcast文档

监听通知栏消息(支持白名单、黑名单、过滤) Ba-NotifyListener文档

全局置灰、哀悼置灰(可动态、同时支持nvue、vue) Ba-Gray文档

获取设备唯一标识(OAID、AAID、IMEI等) Ba-IdCode文档

实时定位(系统、后台运行、支持息屏)插件 Ba-Location文档

猜你喜欢

转载自blog.csdn.net/u013164293/article/details/128182161
今日推荐