Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Only initialize prevCoordinate when we have reasonable accuracy.
Browse files Browse the repository at this point in the history
  • Loading branch information
otsaloma committed Jul 20, 2014
1 parent 8426137 commit 6e7cb5f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions qml/PositionSource.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ PositionSource {
// Calculate direction, since it's missing from gps.position.
// http://bugreports.qt-project.org/browse/QTBUG-36298
var threshold = gps.position.horizontalAccuracy || 15;
if (threshold > 0 && threshold < 30 && gps.prevCoordinate &&
gps.prevCoordinate.distanceTo(gps.position.coordinate) > threshold) {
if (threshold < 0 || threshold > 30) return;
if (!gps.prevCoordinate) {
var x = gps.position.coordinate.longitude;
var y = gps.position.coordinate.latitude;
gps.prevCoordinate = QtPositioning.coordinate(y, x);
} else if (gps.prevCoordinate.distanceTo(
gps.position.coordinate) > threshold) {
gps.direction = gps.prevCoordinate.azimuthTo(gps.position.coordinate);
gps.prevCoordinate.longitude = gps.position.coordinate.longitude;
gps.prevCoordinate.latitude = gps.position.coordinate.latitude;
gps.prevTime = Date.now();
} else if (!gps.prevCoordinate) {
var x = gps.position.coordinate.longitude;
var y = gps.position.coordinate.latitude;
gps.prevCoordinate = QtPositioning.coordinate(y, x);
} else if (gps.direction && Date.now() - gps.prevTime > 5*60*1000) {
gps.direction = undefined;
}
Expand Down

0 comments on commit 6e7cb5f

Please sign in to comment.