|
@@ -4,6 +4,19 @@ import * as TaskManager from 'expo-task-manager';
|
|
|
import request from './RequestUtils';
|
|
import request from './RequestUtils';
|
|
|
import { alert } from './TotastUtils';
|
|
import { alert } from './TotastUtils';
|
|
|
|
|
|
|
|
|
|
+const LOCATION_TASK_NAME = 'background-location-task';
|
|
|
|
|
+
|
|
|
|
|
+TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ // Error occurred - check `error.message` for more details.
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data) {
|
|
|
|
|
+ const { locations } = data;
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ // do something with the locations captured in the background
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
const key = 'c4faf80125b298f93bbc1477db10e69c';
|
|
const key = 'c4faf80125b298f93bbc1477db10e69c';
|
|
|
const tengxunKey = 'GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K';
|
|
const tengxunKey = 'GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K';
|
|
|
|
|
|
|
@@ -14,10 +27,10 @@ async function getLocation() {
|
|
|
return Location.requestPermissionsAsync()
|
|
return Location.requestPermissionsAsync()
|
|
|
.then((res) => {
|
|
.then((res) => {
|
|
|
if (res.status === 'granted') {
|
|
if (res.status === 'granted') {
|
|
|
- return Location.getCurrentPositionAsync({
|
|
|
|
|
- enableHighAccuracy: true,
|
|
|
|
|
- timeout: 30000,
|
|
|
|
|
- accuracy: Location.Accuracy.Highest,
|
|
|
|
|
|
|
+ return Location.getCurrentPositionAsync(LOCATION_TASK_NAME, {
|
|
|
|
|
+ enableHighAccuracy: false,
|
|
|
|
|
+ timeout: 5000,
|
|
|
|
|
+ maximumAge: 10000,
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
return Promise.reject();
|
|
return Promise.reject();
|
|
@@ -59,6 +72,7 @@ async function getLocation() {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.catch((e) => {
|
|
.catch((e) => {
|
|
|
|
|
+ console.log(e);
|
|
|
return Promise.resolve({
|
|
return Promise.resolve({
|
|
|
addressName: '定位失败',
|
|
addressName: '定位失败',
|
|
|
location: {
|
|
location: {
|