Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. private boolean filterAndAddLocation(Location location){
  2.  
  3. long age = getLocationAge(location);
  4.  
  5. if(age > 10 * 1000){ //more than 10 seconds
  6. Log.d(TAG, "Location is old");
  7. oldLocationList.add(location);
  8. return false;
  9. }
  10.  
  11. if(location.getAccuracy() < 0){
  12. Log.d(TAG, "Latitidue and longitude values are invalid.");
  13. noAccuracyLocationList.add(location);
  14. return false;
  15. }
  16.  
  17. //setAccuracy(newLocation.getAccuracy());
  18. float horizontalAccuracy = location.getAccuracy();
  19. if(horizontalAccuracy > 100){
  20. Log.d(TAG, "Accuracy is too low.");
  21. inaccurateLocationList.add(location);
  22. return false;
  23. }
  24.  
  25.  
  26. /* Kalman Filter */
  27. float Qvalue;
  28.  
  29. long locationTimeInMillis = (long)(location.getElapsedRealtimeNanos() / 1000000);
  30. long elapsedTimeInMillis = locationTimeInMillis - runStartTimeInMillis;
  31.  
  32. if(currentSpeed == 0.0f){
  33. Qvalue = 3.0f; //3 meters per second
  34. }else{
  35. Qvalue = currentSpeed; // meters per second
  36. }
  37.  
  38. kalmanFilter.Process(location.getLatitude(), location.getLongitude(), location.getAccuracy(), elapsedTimeInMillis, Qvalue);
  39. double predictedLat = kalmanFilter.get_lat();
  40. double predictedLng = kalmanFilter.get_lng();
  41.  
  42. Location predictedLocation = new Location("");//provider name is unecessary
  43. predictedLocation.setLatitude(predictedLat);//your coords of course
  44. predictedLocation.setLongitude(predictedLng);
  45. float predictedDeltaInMeters = predictedLocation.distanceTo(location);
  46.  
  47. if(predictedDeltaInMeters > 60){
  48. Log.d(TAG, "Kalman Filter detects mal GPS, we should probably remove this from track");
  49. kalmanFilter.consecutiveRejectCount += 1;
  50.  
  51. if(kalmanFilter.consecutiveRejectCount > 3){
  52. kalmanFilter = new KalmanLatLong(3); //reset Kalman Filter if it rejects more than 3 times in raw.
  53. }
  54.  
  55. kalmanNGLocationList.add(location);
  56. return false;
  57. }else{
  58. kalmanFilter.consecutiveRejectCount = 0;
  59. }
  60.  
  61. /* Notifiy predicted location to UI */
  62. Intent intent = new Intent("PredictLocation");
  63. intent.putExtra("location", predictedLocation);
  64. LocalBroadcastManager.getInstance(this.getApplication()).sendBroadcast(intent);
  65.  
  66. Log.d(TAG, "Location quality is good enough.");
  67. currentSpeed = location.getSpeed();
  68. locationList.add(location);
  69.  
  70.  
  71. return true;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement