-
Notifications
You must be signed in to change notification settings - Fork 0
/
backgroundLocation.js
123 lines (107 loc) · 4.5 KB
/
backgroundLocation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// import React, { Component } from 'react';
// import { View, Text } from 'react-native';
// import BackgroundGeolocation from 'react-native-mauron85-background-geolocation';
// export default class BackgroundLocation extends Component {
// componentDidMount() {
// BackgroundGeolocation.configure({
// desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
// stationaryRadius: 50,
// distanceFilter: 50,
// notificationTitle: 'Background tracking',
// notificationText: 'enabled',
// debug: true,
// startOnBoot: false,
// stopOnTerminate: true,
// locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
// interval: 10000,
// fastestInterval: 5000,
// activitiesInterval: 10000,
// stopOnStillActivity: false,
// url: 'http://192.168.81.15:3000/location',
// httpHeaders: {
// 'X-FOO': 'bar',
// },
// // customize post properties
// postTemplate: {
// lat: '@latitude',
// lon: '@longitude',
// foo: 'bar', // you can also add your own properties
// },
// });
// BackgroundGeolocation.on('location', (location) => {
// // handle your locations here
// // to perform long running operation on iOS
// // you need to create background task
// BackgroundGeolocation.startTask((taskKey) => {
// // execute long running task
// // eg. ajax post location
// // IMPORTANT: task has to be ended by endTask
// BackgroundGeolocation.endTask(taskKey);
// });
// });
// BackgroundGeolocation.on('error', (error) => {
// console.log('[ERROR] BackgroundGeolocation error:', error);
// });
// BackgroundGeolocation.on('start', () => {
// console.log('[INFO] BackgroundGeolocation service has been started');
// });
// BackgroundGeolocation.on('stop', () => {
// console.log('[INFO] BackgroundGeolocation service has been stopped');
// });
// BackgroundGeolocation.on('authorization', (status) => {
// console.log(`[INFO] BackgroundGeolocation authorization status: ${status}`);
// if (status !== BackgroundGeolocation.AUTHORIZED) {
// // we need to set delay or otherwise alert may not be shown
// setTimeout(
// () => Alert.alert(
// 'App requires location tracking permission',
// 'Would you like to open app settings?',
// [
// { text: 'Yes', onPress: () => BackgroundGeolocation.showAppSettings() },
// { text: 'No', onPress: () => console.log('No Pressed'), style: 'cancel' },
// ],
// ),
// 1000,
// );
// }
// });
// BackgroundGeolocation.on('background', () => {
// console.log('[INFO] App is in background');
// });
// BackgroundGeolocation.on('foreground', () => {
// console.log('[INFO] App is in foreground');
// });
// BackgroundGeolocation.on('abort_requested', () => {
// console.log('[INFO] Server responded with 285 Updates Not Required');
// // Here we can decide whether we want stop the updates or not.
// // If you've configured the server to return 285, then it means the server does not require further update.
// // So the normal thing to do here would be to `BackgroundGeolocation.stop()`.
// // But you might be counting on it to receive location updates in the UI, so you could just reconfigure and set `url` to null.
// });
// BackgroundGeolocation.on('http_authorization', () => {
// console.log('[INFO] App needs to authorize the http requests');
// });
// BackgroundGeolocation.checkStatus((status) => {
// console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
// console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
// console.log(`[INFO] BackgroundGeolocation auth status: ${status.authorization}`);
// // you don't need to check status before start (this is just the example)
// if (!status.isRunning) {
// BackgroundGeolocation.start(); // triggers start on start event
// }
// });
// // you can also just start without checking for status
// // BackgroundGeolocation.start();
// }
// componentWillUnmount() {
// // unregister all event listeners
// BackgroundGeolocation.removeAllListeners();
// }
// render() {
// return (
// <View>
// <Text>aaaa</Text>
// </View>
// );
// }
// }