澄清分钟距离上LocationManager.requestLocationUpdates方法,最小距离参数 [英] Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance parameter

查看:3904
本文介绍了澄清分钟距离上LocationManager.requestLocationUpdates方法,最小距离参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上研究,发现地点Manager.requestLocationUpdates方法,并看到它了minDistance依旧的参数。定义该网站(的http://blog.doityourselfandroid.com/2010/12/25/understanding-locationlistener-android/)给了我这样的说法是10米一个例子的通知最小间隔距离。任何人都可以澄清这意味着什么?每次我移动10个米一个电话,我得到一个GPS更新?

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?

推荐答案

是的,实际上这意味着,如果平台观察从比 minDistance才会更多您现在的位置所保存的平台最后一个位置,你的听众将获得与更新的位置通知。请注意,这两个位置不一定需要是连续的(即有可能是一些小位移,最终加起来 minDistance才会,并终于超过了位置的门槛将成为一个报告给应用程序)。

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).

实际的平台code能<一个href=\"https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/LocationManagerService.java#L1893\"相对=nofollow>看到在Github上的,这我也粘贴如下:

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;
        }
    }
...

注意 minDistance才会参数只影响时,如果该值大于 0 大于您的应用程序得到通知。

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

另外请注意,所有的定位系统存在误差的显著水平计算位置的时候,所以用小 minDistance才会值,您可能会频繁地收到通知,而且​​这些通知可能是定位计算错误,不正确的用户的移动。

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.

这篇关于澄清分钟距离上LocationManager.requestLocationUpdates方法,最小距离参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆