Coordinates filter works almost fine

Lukasz3 years ago

Hello Anton

I'm testing the coordinates.filter and it works almost fine.
Here is the filter code:

            if (filter && last.getValid() && last.getLatitude() != 0 && last.getLongitude() != 0) {
                boolean satisfiesMin = coordinatesMinError == 0 || distance > coordinatesMinError;
                boolean satisfiesMax = coordinatesMaxError == 0
                        || distance < coordinatesMaxError || position.getValid();
                if (!satisfiesMin || !satisfiesMax) {
                    position.setLatitude(last.getLatitude());
                    position.setLongitude(last.getLongitude());
                    distance = 0;
                }

As you can see for the filter to work last.getValid () must be true.

Theoretical example (for coordinates.maxError).

  • The car is driving on the road, the coordinates are valid
  • The car enters the underground parking lot.
  • The device sends the coordinates 0.0 and the invalid flag.
  • Traccar checks the condition:
(filter && last.getValid () && last.getLatitude ()! = 0 && last.getLongitude ()! = 0)
  • The condition is true because the last coordinates are valid.Everything OK, the filter is working.
  • The device sends the coordinates 0.0 again and the flag invalid.
  • Traccar checks the condition:
(filter && last.getValid () && last.getLatitude ()! = 0 && last.getLongitude ()! = 0)

The condition is false because the last coordinates are invalid. The filter does not work, the coordinates 0.0 appear in the database.

My suggestion to change the condition to:

(filter && last.getLatitude ()! = 0 && last.getLongitude ()! = 0)

This will not break the filter because filter coordinates.maxError only works for invalid.

In order for the coordinates.minError filter to work as it does, you need to change the condition (although in my opinion there is no such need):

boolean satisfiesMin = coordinatesMinError == 0 || distance> coordinatesMinError;
to
boolean satisfiesMin = (coordinatesMinError == 0 || distance> coordinatesMinError) && last.getValid ();

Please think about it, I think such a change will be good for Traccar.

Thanks
Lukasz

Anton Tananaev3 years ago

Coordinates filter is there for completely different purpose than you are trying to use it for. It's there to filter out GPS fluctuations when device is not moving.

Lukasz3 years ago

Thanks for Your answer. You have right about my use. However, see that it is enough for the device to send 2 invalid coordinates and the filter will not work, so it will not prevent GPS fluctuations. Therefore, I ask you to think about the topic (you can kill 2 birds with one stone - my use and better prevention of fluctuations).