D
D
druper2019-02-20 13:53:29
Android
druper, 2019-02-20 13:53:29

How to correctly use Distance Matrix API distance calculation?

Every minute the location is written to the database. the distance between two nearest points is calculated using the Distance Matrix API. then folds up.
I get extra kilometers for a couple of hours driving around the city. or hundreds of meters while I'm stuck in traffic.

private LocationRequest initLocationRequest() {
        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(LOCATION_INTERVAL_SECONDS);
        mLocationRequest.setFastestInterval(LOCATION_INTERVAL_SECONDS / 2);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        return mLocationRequest;
    }

    private void setLocationUpdates() {
        mLocationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                for (Location location : locationResult.getLocations()) { 
                  saveInDb(location );
                }
            }
        };

        initLocationRequest();
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Vasilenko, 2019-02-28
@farewell

I would venture to suggest that your problem is in the "bounce" of the GPS readings, which differ by several meters. You stand in a traffic jam for 10 minutes, for example, and according to the GPS readings, you make 5-10-meter "jumps" near one point.
Take a look at the data. If everything is as I say, screw on the filtering, which will adapt the received data to the speed of your movement.
Start by filtering out data if the distance between them divided by the number of seconds is less than N meters (faster than a walker).
Add a displacement vector to each segment of the path. This will cut off segments of insignificant length that contradict the last significant vector.
Yes, there are many tricks you can think of. It all depends on your situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question