Clarification on min distance on LocationManager.r

2019-07-19 23:32发布

I researched online and saw that Location Manager.requestLocationUpdates method and saw that it took an argument of minDistance. The definition that the site(http://blog.doityourselfandroid.com/2010/12/25/understanding-locationlistener-android/) gave me for that argument was "minimum distance interval for notifications" with an example of 10 meters. Can anyone clarify what that means? Everytime i move 10 meters with a phone, i get an gps update?

1条回答
老娘就宠你
2楼-- · 2019-07-19 23:45

Yes, essentially this means that if the platform observes your current position as being more than minDistance from the last location that was saved by the platform, your listener will get notified with the updated position. Note that these two positions don't necessarily need to be sequential (i.e., there could be a number of small displacements that eventually add up to minDistance, and the location that finally exceeds the threshold will be the one reported to the app).

The actual platform code can be seen on Github, which I've also pasted below:

private static boolean shouldBroadcastSafe(
        Location loc, Location lastLoc, UpdateRecord record, long now) {
    // Always broadcast the first update
    if (lastLoc == null) {
        return true;
    }

    // Check whether sufficient time has passed
    long minTime = record.mRequest.getFastestInterval();
    long delta = (loc.getElapsedRealtimeNanos() - lastLoc.getElapsedRealtimeNanos())
            / NANOS_PER_MILLI;
    if (delta < minTime - MAX_PROVIDER_SCHEDULING_JITTER_MS) {
        return false;
    }

    // Check whether sufficient distance has been traveled
    double minDistance = record.mRequest.getSmallestDisplacement();
    if (minDistance > 0.0) {
        if (loc.distanceTo(lastLoc) <= minDistance) {
            return false;
        }
    }
...

Note that minDistance parameter only affects when your app gets notified if the value is greater than 0.

Also please be aware that with all positioning systems there is a significant level of error when calculating locations, so with small minDistance values you may get notified frequently, but these notifications may be error in positioning calculations, not true user movement.

查看更多
登录 后发表回答