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
5481b52f
Commit
5481b52f
authored
Feb 07, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed a native var. added phonegap-method getStationaryLocation
parent
2bb78b13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+36
-6
BackgroundGeoLocation.js
www/BackgroundGeoLocation.js
+13
-3
No files found.
src/ios/CDVBackgroundGeoLocation.m
View file @
5481b52f
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
NSDate
*
suspendedAt
;
NSDate
*
suspendedAt
;
BOOL
isAcquiringStationaryLocation
;
BOOL
isAcquiringStationaryLocation
;
CLLocation
*
bestS
tationaryLocation
;
CLLocation
*
s
tationaryLocation
;
NSInteger
stationaryLocationAttempts
;
NSInteger
stationaryLocationAttempts
;
CLCircularRegion
*
stationaryRegion
;
CLCircularRegion
*
stationaryRegion
;
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
locationManager
=
[[
CLLocationManager
alloc
]
init
];
locationManager
=
[[
CLLocationManager
alloc
]
init
];
locationManager
.
delegate
=
self
;
locationManager
.
delegate
=
self
;
bestS
tationaryLocation
=
nil
;
s
tationaryLocation
=
nil
;
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onSuspend
:
)
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
onSuspend
:
)
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
...
@@ -152,6 +152,36 @@
...
@@ -152,6 +152,36 @@
}
}
}
}
}
}
/**
* Fetches current stationaryLocation
*/
-
(
void
)
getStationaryLocation
:(
CDVInvokedUrlCommand
*
)
command
{
NSLog
(
@"- CDVBackgroundGeoLocation getStationaryLocation"
);
NSMutableDictionary
*
returnInfo
;
// Build a resultset for javascript callback.
CDVPluginResult
*
result
=
nil
;
if
(
stationaryLocation
)
{
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
9
];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
stationaryLocation
.
timestamp
timeIntervalSince1970
]
*
1000
)];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
speed
]
forKey
:
@"velocity"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
verticalAccuracy
]
forKey
:
@"altitudeAccuracy"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
horizontalAccuracy
]
forKey
:
@"accuracy"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
course
]
forKey
:
@"heading"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
altitude
]
forKey
:
@"altitude"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
coordinate
.
latitude
]
forKey
:
@"latitude"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
stationaryLocation
.
coordinate
.
longitude
]
forKey
:
@"longitude"
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
}
else
{
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
NO
];
}
[
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
*/
*/
...
@@ -217,7 +247,7 @@
...
@@ -217,7 +247,7 @@
[
locationManager
stopUpdatingLocation
];
[
locationManager
stopUpdatingLocation
];
isAcquiringStationaryLocation
=
NO
;
isAcquiringStationaryLocation
=
NO
;
[
locationManager
startMonitoringSignificantLocationChanges
];
[
locationManager
startMonitoringSignificantLocationChanges
];
[
self
startMonitoringStationaryRegion
:
bestS
tationaryLocation
];
[
self
startMonitoringStationaryRegion
:
s
tationaryLocation
];
}
}
// Bail out if there's already a background-task in-effect.
// Bail out if there's already a background-task in-effect.
...
@@ -239,9 +269,9 @@
...
@@ -239,9 +269,9 @@
if
(
stationaryLocationAttempts
==
5
)
{
if
(
stationaryLocationAttempts
==
5
)
{
return
true
;
return
true
;
}
}
if
(
bestStationaryLocation
==
nil
||
bestS
tationaryLocation
.
horizontalAccuracy
>
location
.
horizontalAccuracy
)
{
if
(
stationaryLocation
==
nil
||
s
tationaryLocation
.
horizontalAccuracy
>
location
.
horizontalAccuracy
)
{
// store the location as the "best effort"
// store the location as the "best effort"
bestS
tationaryLocation
=
location
;
s
tationaryLocation
=
location
;
if
(
location
.
horizontalAccuracy
<=
5
.
0
)
{
if
(
location
.
horizontalAccuracy
<=
5
.
0
)
{
return
true
;
return
true
;
}
}
...
@@ -335,7 +365,7 @@
...
@@ -335,7 +365,7 @@
[
locationManager
startUpdatingLocation
];
[
locationManager
startUpdatingLocation
];
}
else
{
}
else
{
// Crank up the GPS power temporarily to get a good fix on our current staionary location in order to set up region-monitoring.
// Crank up the GPS power temporarily to get a good fix on our current staionary location in order to set up region-monitoring.
bestS
tationaryLocation
=
nil
;
s
tationaryLocation
=
nil
;
isAcquiringStationaryLocation
=
YES
;
isAcquiringStationaryLocation
=
YES
;
stationaryLocationAttempts
=
0
;
stationaryLocationAttempts
=
0
;
locationManager
.
distanceFilter
=
kCLDistanceFilterNone
;
locationManager
.
distanceFilter
=
kCLDistanceFilterNone
;
...
...
www/BackgroundGeoLocation.js
View file @
5481b52f
/***
cordova
.
define
(
"
org.transistorsoft.cordova.background-geolocation.BackgroundGeoLocation
"
,
function
(
require
,
exports
,
module
)
{
/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* @author <chris@transistorsoft.com>
* @author <brian@briansamson.com>
* @author <brian@briansamson.com>
...
@@ -78,5 +78,15 @@ module.exports = {
...
@@ -78,5 +78,15 @@ module.exports = {
'
BackgroundGeoLocation
'
,
'
BackgroundGeoLocation
'
,
'
setConfig
'
,
'
setConfig
'
,
[
config
]);
[
config
]);
}
},
};
/**
\ No newline at end of file
* Returns current stationaryLocation if available. null if not
*/
getStationaryLocation
:
function
(
success
,
failure
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
getStationaryLocation
'
,
[]);
}
};});
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