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
f4874a21
Commit
f4874a21
authored
Feb 11, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement automatic distanceFilter calculation based upon speed
parent
d6353953
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletion
+28
-1
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+28
-1
No files found.
src/ios/CDVBackgroundGeoLocation.m
View file @
f4874a21
...
...
@@ -286,6 +286,25 @@
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
sync
:
newLocation
];
}];
// Adjust distanceFilter incrementally based upon current velocity
if
(
isMoving
)
{
float
newDistanceFilter
=
distanceFilter
;
// sanity-check obvious high speed error.
if
(
newLocation
.
speed
>
100
)
{
return
;
}
if
(
newLocation
.
speed
>
5
.
0
)
{
newDistanceFilter
=
[
self
calculateDistanceFilter
:
newLocation
.
speed
];
}
if
(
newDistanceFilter
!=
locationManager
.
distanceFilter
)
{
NSLog
(
@"- CDVBackgroundGeoLocation updated distanceFilter, new: %f, old: %f"
,
newDistanceFilter
,
locationManager
.
distanceFilter
);
[
locationManager
stopUpdatingLocation
];
locationManager
.
distanceFilter
=
newDistanceFilter
;
[
locationManager
startUpdatingLocation
];
}
}
}
-
(
BOOL
)
isBestStationaryLocation
:(
CLLocation
*
)
location
{
stationaryLocationAttempts
++
;
...
...
@@ -308,7 +327,7 @@
*/
-
(
void
)
sync
:(
CLLocation
*
)
location
{
NSLog
(
@"
%f,%f"
,
location
.
coordinate
.
latitude
,
location
.
coordinate
.
longitude
);
NSLog
(
@"
position: %f,%f, speed: %f"
,
location
.
coordinate
.
latitude
,
location
.
coordinate
.
longitude
,
location
.
speed
);
if
(
isDebugging
)
{
AudioServicesPlaySystemSound
(
locationSyncSound
);
}
...
...
@@ -332,6 +351,14 @@
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
}
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10.
*/
-
(
float
)
calculateDistanceFilter
:(
float
)
velocity
{
return
(
5
.
0
*
floorf
(
velocity
/
5
.
0
+
0
.
5
f
))
*
10
;
}
-
(
void
)
stopBackgroundTask
{
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
...
...
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