Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-background-geolocation
Commits
0856e7d9
Commit
0856e7d9
authored
May 22, 2015
by
Chris Scott
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch geofencing
parents
e64e5dae
8f24e6c5
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
136 additions
and
4 deletions
+136
-4
index.html
example/SampleApp/www/index.html
+1
-0
LongPress.js
example/SampleApp/www/js/LongPress.js
+31
-0
index.js
example/SampleApp/www/js/index.js
+35
-1
CDVBackgroundGeoLocation.h
src/ios/CDVBackgroundGeoLocation.h
+3
-0
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+30
-1
TSLocationManager.h
...nManager.framework/Versions/1/Headers/TSLocationManager.h
+4
-0
CodeDirectory
...amework/Versions/1/Resources/_CodeSignature/CodeDirectory
+0
-0
CodeResources
...amework/Versions/1/Resources/_CodeSignature/CodeResources
+2
-2
CodeSignature
...amework/Versions/1/Resources/_CodeSignature/CodeSignature
+0
-0
TSLocationManager
.../TSLocationManager.framework/Versions/1/TSLocationManager
+0
-0
BackgroundGeoLocation.js
www/BackgroundGeoLocation.js
+30
-0
No files found.
example/SampleApp/www/index.html
View file @
0856e7d9
...
@@ -50,6 +50,7 @@
...
@@ -50,6 +50,7 @@
<script
type=
"text/javascript"
src=
"cordova.js"
></script>
<script
type=
"text/javascript"
src=
"cordova.js"
></script>
<script
type=
"text/javascript"
src=
"js/jquery-2.1.1.js"
></script>
<script
type=
"text/javascript"
src=
"js/jquery-2.1.1.js"
></script>
<script
type=
"text/javascript"
src=
"js/LongPress.js"
></script>
<script
type=
"text/javascript"
src=
"js/index.js"
></script>
<script
type=
"text/javascript"
src=
"js/index.js"
></script>
</body>
</body>
</html>
</html>
example/SampleApp/www/js/LongPress.js
0 → 100644
View file @
0856e7d9
/**
* Custom google-maps @event LongClick hack.
*/
function
LongPress
(
map
,
maxTime
)
{
this
.
maxTime
=
maxTime
;
this
.
isDragging
=
false
;
var
me
=
this
;
me
.
map
=
map
;
google
.
maps
.
event
.
addListener
(
map
,
'
mousedown
'
,
function
(
e
)
{
me
.
onMouseDown_
(
e
);
});
google
.
maps
.
event
.
addListener
(
map
,
'
mouseup
'
,
function
(
e
)
{
me
.
onMouseUp_
(
e
);
});
google
.
maps
.
event
.
addListener
(
map
,
'
drag
'
,
function
(
e
)
{
me
.
onMapDrag_
(
e
);
});
}
LongPress
.
prototype
.
onMouseUp_
=
function
(
e
)
{
var
now
=
+
new
Date
;
if
(
now
-
this
.
downTime
>
this
.
maxTime
&&
this
.
isDragging
===
false
)
{
google
.
maps
.
event
.
trigger
(
this
.
map
,
'
longpress
'
,
e
);
}
}
LongPress
.
prototype
.
onMouseDown_
=
function
()
{
this
.
downTime
=
+
new
Date
;
this
.
isDragging
=
false
;
}
LongPress
.
prototype
.
onMapDrag_
=
function
(
e
)
{
this
.
isDragging
=
true
;
};
example/SampleApp/www/js/index.js
View file @
0856e7d9
...
@@ -54,6 +54,10 @@ var app = {
...
@@ -54,6 +54,10 @@ var app = {
*/
*/
currentLocation
:
null
,
currentLocation
:
null
,
/**
/**
* @property geofence {google.maps.Cirlce}
*/
geofence
:
undefined
,
/**
* @private
* @private
*/
*/
btnEnabled
:
undefined
,
btnEnabled
:
undefined
,
...
@@ -83,6 +87,9 @@ var app = {
...
@@ -83,6 +87,9 @@ var app = {
canvas
.
width
(
window
.
clientWidth
);
canvas
.
width
(
window
.
clientWidth
);
app
.
map
=
new
google
.
maps
.
Map
(
canvas
[
0
],
mapOptions
);
app
.
map
=
new
google
.
maps
.
Map
(
canvas
[
0
],
mapOptions
);
// Add custom LongPress event to google map so we can add Geofences with longpress event!
new
LongPress
(
app
.
map
,
500
);
},
},
// Bind Event Listeners
// Bind Event Listeners
//
//
...
@@ -188,7 +195,7 @@ var app = {
...
@@ -188,7 +195,7 @@ var app = {
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
desiredAccuracy
:
0
,
desiredAccuracy
:
0
,
stationaryRadius
:
50
,
stationaryRadius
:
50
,
distanceFilter
:
50
,
distanceFilter
:
25
,
disableElasticity
:
false
,
// <-- [iOS] Default is 'false'. Set true to disable speed-based distanceFilter elasticity
disableElasticity
:
false
,
// <-- [iOS] Default is 'false'. Set true to disable speed-based distanceFilter elasticity
locationUpdateInterval
:
5000
,
locationUpdateInterval
:
5000
,
minimumActivityRecognitionConfidence
:
80
,
// 0-100%. Minimum activity-confidence for a state-change
minimumActivityRecognitionConfidence
:
80
,
// 0-100%. Minimum activity-confidence for a state-change
...
@@ -214,6 +221,33 @@ var app = {
...
@@ -214,6 +221,33 @@ var app = {
}
}
});
});
bgGeo
.
onGeofence
(
function
(
identifier
)
{
alert
(
'
Enter Geofence:
'
+
identifier
);
console
.
log
(
'
[js] Geofence ENTER:
'
,
identifier
);
});
// Add longpress event for adding GeoFence of hard-coded radius 200m.
google
.
maps
.
event
.
addListener
(
app
.
map
,
'
longpress
'
,
function
(
e
)
{
if
(
app
.
geofence
)
{
app
.
geofence
.
setMap
(
null
);
}
bgGeo
.
addGeofence
({
identifier
:
'
MyGeofence
'
,
radius
:
200
,
latitude
:
e
.
latLng
.
lat
(),
longitude
:
e
.
latLng
.
lng
()
},
function
()
{
app
.
geofence
=
new
google
.
maps
.
Circle
({
fillColor
:
'
#00cc00
'
,
fillOpacity
:
0.4
,
strokeOpacity
:
0
,
radius
:
200
,
center
:
e
.
latLng
,
map
:
app
.
map
});
})
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
var
settings
=
ENV
.
settings
;
var
settings
=
ENV
.
settings
;
...
...
src/ios/CDVBackgroundGeoLocation.h
View file @
0856e7d9
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
@interface
CDVBackgroundGeolocation
:
CDVPlugin
@interface
CDVBackgroundGeolocation
:
CDVPlugin
@property
(
nonatomic
,
strong
)
NSString
*
syncCallbackId
;
@property
(
nonatomic
,
strong
)
NSString
*
syncCallbackId
;
@property
(
nonatomic
,
strong
)
NSString
*
geofenceCallbackId
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
stationaryRegionListeners
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
stationaryRegionListeners
;
-
(
void
)
configure
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
configure
:(
CDVInvokedUrlCommand
*
)
command
;
...
@@ -24,5 +25,7 @@
...
@@ -24,5 +25,7 @@
-
(
void
)
sync
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
sync
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
getOdometer
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
getOdometer
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
resetOdometer
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
resetOdometer
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
addGeofence
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
onGeofence
:(
CDVInvokedUrlCommand
*
)
command
;
@end
@end
src/ios/CDVBackgroundGeoLocation.m
View file @
0856e7d9
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
NSDictionary
*
config
;
NSDictionary
*
config
;
}
}
@synthesize
syncCallbackId
,
stationaryRegionListeners
;
@synthesize
syncCallbackId
,
geofenceCallbackId
,
stationaryRegionListeners
;
-
(
void
)
pluginInitialize
-
(
void
)
pluginInitialize
{
{
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onLocationChanged
:
)
name
:
@"TSLocationManager.location"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onLocationChanged
:
)
name
:
@"TSLocationManager.location"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onStationaryLocation
:
)
name
:
@"TSLocationManager.stationary"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onStationaryLocation
:
)
name
:
@"TSLocationManager.stationary"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onEnterGeofence
:
)
name
:
@"TSLocationManager.geofence"
object
:
nil
];
}
}
/**
/**
...
@@ -114,6 +115,17 @@
...
@@ -114,6 +115,17 @@
[
bgGeo
stopBackgroundTask
];
[
bgGeo
stopBackgroundTask
];
}
}
-
(
void
)
onEnterGeofence
:(
NSNotification
*
)
notification
{
if
(
self
.
geofenceCallbackId
==
nil
)
{
return
;
}
CLCircularRegion
*
region
=
notification
.
object
;
CDVPluginResult
*
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsString
:
region
.
identifier
];
[
result
setKeepCallbackAsBool
:
YES
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
self
.
geofenceCallbackId
];
}
/**
/**
* Fetches current stationaryLocation
* Fetches current stationaryLocation
*/
*/
...
@@ -160,6 +172,23 @@
...
@@ -160,6 +172,23 @@
[
self
.
stationaryRegionListeners
addObject
:
command
.
callbackId
];
[
self
.
stationaryRegionListeners
addObject
:
command
.
callbackId
];
}
}
-
(
void
)
addGeofence
:(
CDVInvokedUrlCommand
*
)
command
{
NSDictionary
*
cfg
=
[
command
.
arguments
objectAtIndex
:
0
];
[
bgGeo
addGeofence
:[
cfg
objectForKey
:
@"identifier"
]
radius:
[[
cfg
objectForKey
:
@"radius"
]
doubleValue
]
latitude:
[[
cfg
objectForKey
:
@"latitude"
]
doubleValue
]
longitude:
[[
cfg
objectForKey
:
@"longitude"
]
doubleValue
]
];
CDVPluginResult
*
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}
-
(
void
)
onGeofence
:(
CDVInvokedUrlCommand
*
)
command
{
self
.
geofenceCallbackId
=
command
.
callbackId
;
}
/**
/**
* Called by js to signify the end of a background-geolocation event
* Called by js to signify the end of a background-geolocation event
*/
*/
...
...
src/ios/TSLocationManager.framework/Versions/1/Headers/TSLocationManager.h
View file @
0856e7d9
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
@interface
TSLocationManager
:
NSObject
<
CLLocationManagerDelegate
>
@interface
TSLocationManager
:
NSObject
<
CLLocationManagerDelegate
>
@property
(
nonatomic
)
CLLocationDistance
odometer
;
-
(
void
)
configure
:(
NSDictionary
*
)
config
;
-
(
void
)
configure
:(
NSDictionary
*
)
config
;
-
(
void
)
start
;
-
(
void
)
start
;
-
(
void
)
stop
;
-
(
void
)
stop
;
...
@@ -19,5 +21,7 @@
...
@@ -19,5 +21,7 @@
-
(
void
)
onAppTerminate
;
-
(
void
)
onAppTerminate
;
-
(
BOOL
)
isEnabled
;
-
(
BOOL
)
isEnabled
;
-
(
NSDictionary
*
)
locationToDictionary
:(
CLLocation
*
)
location
;
-
(
NSDictionary
*
)
locationToDictionary
:(
CLLocation
*
)
location
;
-
(
void
)
addGeofence
:(
NSString
*
)
identifier
radius
:(
CLLocationDistance
)
radius
latitude
:(
CLLocationDegrees
)
latitude
longitude
:(
CLLocationDegrees
)
longitude
;
@end
@end
src/ios/TSLocationManager.framework/Versions/1/Resources/_CodeSignature/CodeDirectory
View file @
0856e7d9
No preview for this file type
src/ios/TSLocationManager.framework/Versions/1/Resources/_CodeSignature/CodeResources
View file @
0856e7d9
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<dict>
<dict>
<key>
Headers/TSLocationManager.h
</key>
<key>
Headers/TSLocationManager.h
</key>
<data>
<data>
uXAE4LxGF9ekkpUCvnRgTZf4wvM
=
93eNJDqyN5vuBJn9oYeT7lb2x1w
=
</data>
</data>
<key>
Info.plist
</key>
<key>
Info.plist
</key>
<data>
<data>
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
<dict>
<dict>
<key>
Headers/TSLocationManager.h
</key>
<key>
Headers/TSLocationManager.h
</key>
<data>
<data>
uXAE4LxGF9ekkpUCvnRgTZf4wvM
=
93eNJDqyN5vuBJn9oYeT7lb2x1w
=
</data>
</data>
<key>
Modules/module.modulemap
</key>
<key>
Modules/module.modulemap
</key>
<data>
<data>
...
...
src/ios/TSLocationManager.framework/Versions/1/Resources/_CodeSignature/CodeSignature
View file @
0856e7d9
No preview for this file type
src/ios/TSLocationManager.framework/Versions/1/TSLocationManager
View file @
0856e7d9
No preview for this file type
www/BackgroundGeoLocation.js
View file @
0856e7d9
...
@@ -156,6 +156,36 @@ module.exports = {
...
@@ -156,6 +156,36 @@ module.exports = {
'
resetOdometer
'
,
'
resetOdometer
'
,
[]);
[]);
},
},
/**
* add geofence
*/
addGeofence
:
function
(
config
,
success
,
failure
)
{
config
=
config
||
{};
if
(
!
config
.
identifier
)
{
throw
"
#addGeofence requires an 'identifier'
"
;
}
if
(
!
(
config
.
latitude
&&
config
.
longitude
))
{
throw
"
#addGeofence requires a #latitude and #longitude
"
;
}
if
(
!
config
.
radius
)
{
throw
"
#addGeofence requires a #radius
"
;
}
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
addGeofence
'
,
[
config
]);
},
onGeofence
:
function
(
success
,
failure
)
{
if
(
!
typeof
(
success
)
===
'
function
'
)
{
throw
"
#onGeofence requires a success callback
"
;
}
exec
(
success
,
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
onGeofence
'
,
[]);
},
_setTimestamp
:
function
(
rs
)
{
_setTimestamp
:
function
(
rs
)
{
// Transform timestamp to Date instance.
// Transform timestamp to Date instance.
if
(
typeof
(
rs
)
===
'
object
'
)
{
if
(
typeof
(
rs
)
===
'
object
'
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment