-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocation.js
79 lines (69 loc) · 2.44 KB
/
geolocation.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
/**
* Wrapper for the geolocation API in Cordova.
* The geolocation object provides access to location based data on the device's GPS sensor or inferred from network signals.
*
* @author Brian Milton
* @version 1.0.0
*
* Important information
* ---------------------
* Device object:
* model : The device's model name (DOMString).
* cordova : The verison of Cordova running on the device (DOMString).
* platform : The device's operating system name (DOMString).
* uuid : The device's Universally Unique Identifier (DOMString).
* verison : The device's operating system version (DOMString).
* name (deprecated) : The device's model name (DOMString).
*/
define(["troopjs/component/widget"], function geolocationWrapper(Widget) {
var DEVICE_READY = false;
var WATCH_ID;
function geoSuccess(location) {
var me = this;
location.isSuccess = true;
me.publish("cordova/geoUpdate",location);
}
function geoFailure(error) {
var me = this;
error.isSuccess = false;
me.publish("cordova/geoUpdate",error);
}
return Widget.extend({
"dom:memory/deviceready" : function deviceReady() {
var me = this;
me[DEVICE_READY] = true;
},
"hub:memory/cordova/getCurrentPosition" : function getCurrentPosition(geoOptions) {
var me = this;
if(me[DEVICE_READY]){
return navigator.geolocation.getCurrentPosition(function(position) {
position.isSuccess = true;
return position;
}, function(error) {
error.isSucces = false;
return error;
}, geoOptions)
} else {
return false;
}
},
"hub:memory/cordova/watchPosition" : function watchLocation(geoOptions) {
var me = this;
if(me[DEVICE_READY]) {
me[WATCH_ID] = navigator.geolocation.watchPosition(geoSuccess,geoFailure,geoOptions);
return true;
} else {
return false;
}
},
"hub:memory/cordova/stopWatchPosition" : function clearLocation() {
var me = this;
if(me[DEVICE_READY]) {
navigator.geolocation.clearWatch(me[WATCH_ID]);
return true;
} else {
return false;
}
}
});
});