Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-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-plugin-background-geolocation
Commits
10402f75
Commit
10402f75
authored
Jan 15, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add setConfig method to allow modification of geolocation params in real-time
parent
e09a4fb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
27 deletions
+80
-27
CDVBackgroundGeoLocation.h
src/ios/CDVBackgroundGeoLocation.h
+1
-0
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+59
-27
BackgroundGeoLocation.js
www/BackgroundGeoLocation.js
+20
-0
No files found.
src/ios/CDVBackgroundGeoLocation.h
View file @
10402f75
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
-
(
void
)
finish
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
finish
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
onPaceChange
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
onPaceChange
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
setStationaryRadius
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
setStationaryRadius
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
setDesiredAccuracy
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
setDistanceFilter
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
setDistanceFilter
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
sync
:(
CLLocation
*
)
location
;
-
(
void
)
sync
:(
CLLocation
*
)
location
;
...
...
src/ios/CDVBackgroundGeoLocation.m
View file @
10402f75
...
@@ -19,14 +19,14 @@
...
@@ -19,14 +19,14 @@
NSNumber
*
maxBackgroundHours
;
NSNumber
*
maxBackgroundHours
;
CLLocationManager
*
locationManager
;
CLLocationManager
*
locationManager
;
CDVLocationData
*
locationData
;
CDVLocationData
*
locationData
;
NSDate
*
suspendedAt
;
NSDate
*
suspendedAt
;
CLCircularRegion
*
myRegion
;
CLCircularRegion
*
myRegion
;
NSInteger
stationaryRadius
;
NSInteger
stationaryRadius
;
NSInteger
distanceFilter
;
NSInteger
distanceFilter
;
NSInteger
locationTimeout
;
NSInteger
desiredAccuracy
;
NSInteger
desiredAccuracy
;
NSInteger
locationTimeout
;
}
}
-
(
void
)
pluginInitialize
-
(
void
)
pluginInitialize
...
@@ -59,28 +59,12 @@
...
@@ -59,28 +59,12 @@
distanceFilter
=
[[
command
.
arguments
objectAtIndex
:
3
]
intValue
];
distanceFilter
=
[[
command
.
arguments
objectAtIndex
:
3
]
intValue
];
locationTimeout
=
[[
command
.
arguments
objectAtIndex
:
4
]
intValue
];
locationTimeout
=
[[
command
.
arguments
objectAtIndex
:
4
]
intValue
];
desiredAccuracy
=
[[
command
.
arguments
objectAtIndex
:
5
]
intValue
];
desiredAccuracy
=
[[
command
.
arguments
objectAtIndex
:
5
]
intValue
];
syncCallbackId
=
command
.
callbackId
;
syncCallbackId
=
command
.
callbackId
;
// Set a movement threshold for new events.
// Set a movement threshold for new events.
locationManager
.
activityType
=
CLActivityTypeOther
;
locationManager
.
activityType
=
CLActivityTypeOther
;
locationManager
.
pausesLocationUpdatesAutomatically
=
YES
;
locationManager
.
pausesLocationUpdatesAutomatically
=
YES
;
switch
(
desiredAccuracy
)
{
case
1000
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyKilometer
;
break
;
case
100
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyHundredMeters
;
break
;
case
10
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyNearestTenMeters
;
break
;
case
0
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyBest
;
break
;
}
locationManager
.
distanceFilter
=
distanceFilter
;
// meters
locationManager
.
distanceFilter
=
distanceFilter
;
// meters
myRegion
=
nil
;
myRegion
=
nil
;
...
@@ -102,7 +86,7 @@
...
@@ -102,7 +86,7 @@
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
NSLog
(
@"- CDVBackgroundGeoLocation start (background? %d)"
,
state
);
NSLog
(
@"- CDVBackgroundGeoLocation start (background? %d)"
,
state
);
if
(
state
==
UIApplicationStateBackground
)
{
if
(
state
==
UIApplicationStateBackground
)
{
[
self
setPace
:
isMoving
];
[
self
setPace
:
isMoving
];
}
}
...
@@ -126,7 +110,7 @@
...
@@ -126,7 +110,7 @@
{
{
isMoving
=
[[
command
.
arguments
objectAtIndex
:
0
]
boolValue
];
isMoving
=
[[
command
.
arguments
objectAtIndex
:
0
]
boolValue
];
NSLog
(
@"- CDVBackgroundGeoLocation onPaceChange %hhd"
,
isMoving
);
NSLog
(
@"- CDVBackgroundGeoLocation onPaceChange %hhd"
,
isMoving
);
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
if
(
state
==
UIApplicationStateBackground
)
{
if
(
state
==
UIApplicationStateBackground
)
{
[
self
setPace
:
isMoving
];
[
self
setPace
:
isMoving
];
...
@@ -140,6 +124,11 @@
...
@@ -140,6 +124,11 @@
stationaryRadius
=
[[
command
.
arguments
objectAtIndex
:
0
]
intValue
];
stationaryRadius
=
[[
command
.
arguments
objectAtIndex
:
0
]
intValue
];
NSLog
(
@"- CDVBackgroundGeoLocation setStationaryRadius %d"
,
stationaryRadius
);
NSLog
(
@"- CDVBackgroundGeoLocation setStationaryRadius %d"
,
stationaryRadius
);
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
if
(
state
==
UIApplicationStateBackground
)
{
[
self
setPace
:
isMoving
];
}
CDVPluginResult
*
result
=
nil
;
CDVPluginResult
*
result
=
nil
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
...
@@ -152,11 +141,32 @@
...
@@ -152,11 +141,32 @@
distanceFilter
=
[[
command
.
arguments
objectAtIndex
:
0
]
intValue
];
distanceFilter
=
[[
command
.
arguments
objectAtIndex
:
0
]
intValue
];
NSLog
(
@"- CDVBackgroundGeoLocation setDistanceFilter %d"
,
distanceFilter
);
NSLog
(
@"- CDVBackgroundGeoLocation setDistanceFilter %d"
,
distanceFilter
);
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
if
(
state
==
UIApplicationStateBackground
)
{
[
self
setPace
:
isMoving
];
}
CDVPluginResult
*
result
=
nil
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}
/**
* Change stationary radius
*/
-
(
void
)
setDesiredAccuracy
:(
CDVInvokedUrlCommand
*
)
command
{
desiredAccuracy
=
[[
command
.
arguments
objectAtIndex
:
0
]
intValue
];
NSLog
(
@"- CDVBackgroundGeoLocation setDesiredAccuracy %d"
,
desiredAccuracy
);
UIApplicationState
state
=
[[
UIApplication
sharedApplication
]
applicationState
];
if
(
state
==
UIApplicationStateBackground
)
{
[
self
setPace
:
isMoving
];
}
CDVPluginResult
*
result
=
nil
;
CDVPluginResult
*
result
=
nil
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
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
*/
*/
...
@@ -201,7 +211,7 @@
...
@@ -201,7 +211,7 @@
NSLog
(
@" Abort: found existing background-task"
);
NSLog
(
@" Abort: found existing background-task"
);
return
;
return
;
}
}
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
[
self
stopBackgroundTask
];
[
self
stopBackgroundTask
];
}];
}];
...
@@ -218,7 +228,7 @@
...
@@ -218,7 +228,7 @@
-
(
void
)
sync
:(
CLLocation
*
)
location
-
(
void
)
sync
:(
CLLocation
*
)
location
{
{
// Fetch last recorded location
// Fetch last recorded location
NSMutableDictionary
*
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
8
];
NSMutableDictionary
*
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
8
];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
location
.
timestamp
timeIntervalSince1970
]
*
1000
)];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
location
.
timestamp
timeIntervalSince1970
]
*
1000
)];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
...
@@ -235,7 +245,7 @@
...
@@ -235,7 +245,7 @@
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
[
result
setKeepCallbackAsBool
:
YES
];
[
result
setKeepCallbackAsBool
:
YES
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
}
}
-
(
void
)
stopBackgroundTask
-
(
void
)
stopBackgroundTask
...
@@ -283,8 +293,30 @@
...
@@ -283,8 +293,30 @@
*/
*/
-
(
void
)
setPace
:(
BOOL
)
value
-
(
void
)
setPace
:(
BOOL
)
value
{
{
NSLog
(
@"- CDVBackgroundGeoLocation setPace %d"
,
value
);
// When stationaryRadius is 0, don't use sig.changes -- keep GPS on constantly.
isMoving
=
value
;
isMoving
=
(
stationaryRadius
==
0
)
?
YES
:
value
;
NSLog
(
@"- CDVBackgroundGeoLocation setPace"
);
NSLog
(
@" isMoving %d"
,
isMoving
);
NSLog
(
@" desiredAccuracy: %d"
,
desiredAccuracy
);
NSLog
(
@" distanceFilter: %d"
,
distanceFilter
);
NSLog
(
@" stationaryRadius: %d"
,
stationaryRadius
);
switch
(
desiredAccuracy
)
{
case
1000
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyKilometer
;
break
;
case
100
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyHundredMeters
;
break
;
case
10
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyNearestTenMeters
;
break
;
case
0
:
locationManager
.
desiredAccuracy
=
kCLLocationAccuracyBest
;
break
;
}
if
(
myRegion
!=
nil
)
{
if
(
myRegion
!=
nil
)
{
[
locationManager
stopMonitoringForRegion
:
myRegion
];
[
locationManager
stopMonitoringForRegion
:
myRegion
];
myRegion
=
nil
;
myRegion
=
nil
;
...
...
www/BackgroundGeoLocation.js
View file @
10402f75
...
@@ -66,6 +66,19 @@ module.exports = {
...
@@ -66,6 +66,19 @@ module.exports = {
'
onPaceChange
'
,
'
onPaceChange
'
,
[
isMoving
]);
[
isMoving
]);
},
},
/**
* @param {Integer} stationaryRadius
* @param {Integer} desiredAccuracy
* @param {Integer} distanceFilter
* @param {Integer} timeout
*/
setConfig
:
function
(
success
,
failure
,
config
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
setConfig
'
,
[
config
]);
},
setStationaryRadius
:
function
(
value
,
success
,
failure
)
{
setStationaryRadius
:
function
(
value
,
success
,
failure
)
{
exec
(
success
||
function
()
{},
exec
(
success
||
function
()
{},
failure
||
function
()
{},
failure
||
function
()
{},
...
@@ -73,6 +86,13 @@ module.exports = {
...
@@ -73,6 +86,13 @@ module.exports = {
'
setStationaryRadius
'
,
'
setStationaryRadius
'
,
[
value
]);
[
value
]);
},
},
setDesiredAccuracy
:
function
(
value
,
success
,
failure
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
setDesiredAccuracy
'
,
[
value
]);
},
setDistanceFilter
:
function
(
value
,
success
,
failure
)
{
setDistanceFilter
:
function
(
value
,
success
,
failure
)
{
exec
(
success
||
function
()
{},
exec
(
success
||
function
()
{},
failure
||
function
()
{},
failure
||
function
()
{},
...
...
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