-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
102 lines (98 loc) · 2.64 KB
/
app.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
GeoLog = new Mongo.Collection('geo_log');
if (Meteor.isServer) {
Meteor.startup(function() {
Meteor.publish('basic', function () {
return GeoLog.find({}, {
fields: {userId: 0},
sort: {created: 1},
limit: 100
});
});
Meteor.methods({
clear: function() {
GeoLog.remove({});
}
});
});
}
if (Meteor.isClient) {
Meteor.startup(function() {
Meteor.subscribe('basic');
Template.footer.helpers({
isCordova: function() {
return Meteor.isCordova;
}
});
Template.footer.events({
'click #getNow': function() {
if (Meteor.isCordova) {
// cordova
GeolocationFG.get(function(location) {
GeoLog.insert({
location: location,
uuid: GeolocationBG.uuid(),
device: GeolocationBG.device(),
userId: Meteor.userId(),
created: new Date()
});
});
return;
}
// browser
GeolocationFG.get(function(location) {
GeoLog.insert({
location: location.coords,
uuid: 'browser',
device: 'browser',
userId: Meteor.userId(),
created: new Date()
});
});
},
'click #getBackground': function(event) {
var btn = event.currentTarget;
var dest = document.getElementById('btnFeedback');
if (!Meteor.isCordova) {
dest.innerHTML = 'Not Available, Not Cordova';
return;
}
if (!GeolocationBG.isStarted) {
if (!GeolocationBG.start()) {
dest.innerHTML = 'ERROR: Not Started, unable to start';
return;
}
if (!GeolocationBG.isStarted) {
dest.innerHTML = 'ERROR: Not Started, status = false';
return;
}
dest.innerHTML = 'Started (every few minutes there should be an update)';
btn.innerHTML = 'Stop';
return;
}
if (!GeolocationBG.stop()) {
dest.innerHTML = 'ERROR: Not Stopped, unable to stop';
return;
}
if (GeolocationBG.isStarted) {
dest.innerHTML = 'ERROR: Not Stopped, status = true';
return;
}
dest.innerHTML = 'Stopped';
btn.innerHTML = 'Start';
return;
},
'click #clear': function(event) {
Meteor.call('clear');
return;
}
});
});
}
if (Meteor.isCordova) {
GeolocationBG.config({
url: 'https://geolocationbackgroundexample.meteor.com/api/geolocation',
debug: true
});
// triggered by a start button
// GeolocationBG.start();
}