Introduction ( download address )
Ba-Location is a system GPS real-time positioning plug-in, which can run in the background, off-screen, and can be used on the intranet.
This plugin comes with a keep-alive technology, if you need to keep alive, please use Ba-KeepAlive .
Note: GPS positioning does not support indoor positioning, it is recommended to test outdoors or in a window.
- Support setting the location information update cycle, in seconds
- Support setting the minimum distance of position change: when the position distance changes beyond this value, the position information will be updated
screenshot display
Instructions
script
Introduce components in
const location = uni.requireNativePlugin('Ba-Location')
script
Called in (example reference, you can modify it according to your own business and calling method)
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 list
method name | illustrate |
---|---|
start | Turn on location services |
stop | stop location services |
subLocation | Subscribe to location information |
isLocationService | Whether the location service is turned on |
isLocationEnable | Whether the positioning switch is turned on |
goSetting | Jump to location service setting interface |
subLocationStatus | Subscribe to location status changes |
subGpsStatus | Subscribe to GPS status (such as Search Star) |
start method parameter
Turn on location services
attribute name | type | required | Defaults | illustrate |
---|---|---|---|---|
minTimeMs | Number | false | 30 | Location information update cycle, in seconds |
minDistanceM | Number | false | 1 | The minimum distance of position change, unit M: when the position distance change exceeds this value, the position information will be updated |
altitudeRequired | Boolean | false | false | Do you need altitude information |
bearingRequired | Boolean | false | false | Do you need orientation information? |
speedRequired | Boolean | false | false | Do you need speed |
isNotification | Boolean | false | true | Whether to enable the notification, it is recommended to enable it, it has a certain effect of keeping alive, the default is true |
subLocation receives parameters
Subscribe location information, res.data
attribute name | type | illustrate |
---|---|---|
longitude | Number | longitude |
latitude | Number | latitude |
time | Number | time |
speed | Number | speed |
altitude | Number | Altitude, in m |
bearing | Number | position |
accuracy | Number | location accuracy |
Series plug-in
Image selection plugin Ba-MediaPicker ( documentation )
Image editing plugin Ba-ImageEditor ( documentation )
File picker plugin Ba-FilePicker ( documentation )
Application message notification plug-in (multiple styles, new support for resident notification mode) Ba-Notify ( documentation )
Apply the unread badge plugin Ba-Shortcut-Badge ( documentation )
Applying the Ba-Autoboot plugin ( documentation )
Scan code native plug-in (millisecond level, support multi-code) Ba-Scanner-G ( documentation )
Native plug-in for scanning code - new (can customize the interface version arbitrarily; support continuous scanning code; support setting scanning code format) Ba-Scanner ( documentation )
Dynamically modify the status bar, navigation bar background color, font color plug-in Ba-AppBar ( documentation )
Native sqlite local database management Ba-Sqlite ( documentation )
Android keep-alive plug-in (using a variety of mainstream technologies) Ba-KeepAlive ( documentation )
Android shortcut (desktop long press app icon) Ba-Shortcut ( documentation )
Custom image watermark (anywhere) Ba-Watermark ( documentation )
The closest image compression plug-in to WeChat is Ba-ImageCompressor ( documentation )
Video compression, video editing plug-in Ba-VideoCompressor ( documentation )
Dynamically switch application icons and names (such as New Year, National Day, etc.) Ba-ChangeIcon ( documentation )
Native Toast pop-up prompt (through all interfaces, through native; custom colors, icons) Ba-Toast ( documentation )
Image graffiti, brush Ba-ImagePaint ( documentation )
pdf reading (gesture zoom, display page number) Ba-Pdf ( documentation )
Sound reminder, vibration reminder, voice broadcast Ba-Beep ( documentation )
Websocket native service (automatic reconnection, heartbeat detection) Ba-Websocket ( documentation )
SMS monitoring (verification code) Ba-Sms ( documentation )
Smart Install (Automatic Upgrade) Ba-SmartUpgrade ( documentation )
Monitor system broadcast, custom broadcast Ba-Broadcast ( documentation )
Listen to notification bar messages (support whitelist, blacklist, filter) Ba-NotifyListener ( documentation )
Global graying, mourning graying (dynamic, support nvue, vue at the same time) Ba-Gray ( documentation )
Get Device Unique Identifier (OAID, AAID, IMEI, etc.) Ba-IdCode ( documentation )
Real-time positioning (system, background operation, support screen) plug-in Ba-Location ( documentation )