在Android的requestLocationUpdates区间 [英] requestLocationUpdates interval in Android

查看:1356
本文介绍了在Android的requestLocationUpdates区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到正确的速度为onLocationChanged功能的更新,这是我的类:

I try to get the correct speed in updates for the function onLocationChanged, this is my class:

public class LocationService extends Service implements LocationListener {

把minTime上6000没有帮助,它西港岛线不断更新不断,我究竟做错了什么?

Putting the minTime on 6000 does not help, it wil keep updating constantly, what am i doing wrong?

public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener, Looper looper) {

问候

推荐答案

该minTime仅仅是一个暗示为LocationProvider,这并不意味着你的位置监听器将被调用一次,每6秒。您将获得更多的位置更新,它到你的code,以挑选出最准确的。

The minTime is just a hint for the LocationProvider, and it doesn't mean that your location listener will be called once every 6 seconds. You will receive more location updates, and its up to your code to pick the most accurate one.

监控手机上的GPS图标。调用到requestLocationUpdates将触发GPS要找准自己的位置,它会发送一个或多个位置更新到LocationListener的,如果它能够得到修复。 (在这一点上,你的GPS图标应该,因为它搜索的位置动画)。

Monitor the GPS icon on your phone. A call to requestLocationUpdates will trigger the GPS to pinpoint your location, and it will send one or more location updates to the locationlistener if it's able to get a fix. (At this point, your GPS icon should be animated as it searches for a location).

在这段时间里,你的LocationListener的可能会收到多个位置更新。您的code可以去挑选最准确的位置,只处理一个。

During that time, your locationlistener may receive several location updates. Your code can go and pick the most accurate location, and process only that one.

在该GPS已经发送了位置更新(S)到您的收听,应该有一段时间不活动。 (您的GPS图标应该消失了几秒钟)。这一段时间不活动应该与minTime对应。对GPS的状态也将发生变化,因为它会被放入TEMPORARILY_UNAVAILABLE。

After the GPS has sent the location update(s) to your listener, there should be a period of inactivity. (your GPS icon should disappear for a couple of seconds). This period of inactivity should correspond with your minTime. The status of the GPS will also change, as it will be put into TEMPORARILY_UNAVAILABLE.

其后,将重复相同的处理。 (全球定位系统可用时,你会再次收到一个或多个位置更新)。

After that, the same process is repeated. (The GPS becomes AVAILABLE, and you'll again receive one or more location updates).

还要考虑到,如果GPS无法获取位置锁定,GPS的图标将保持活跃了,然后6秒,但是你不会接收位置更新。

Also take into account, if the GPS is unable to get a location fix, the GPS icon will remain active for more then 6 seconds, but you won't be receiving location updates.

您还可以监视通过你的监听你的GPS供应商的地位,通过以下方式:

You can also monitor the status of your GPS provider through your listener, via the following method :

public void onStatusChanged(String provider, int status, Bundle extras) {}

状态是android.location.LocationProvider定义的以下常量之一

The status is one of the following constants defined on android.location.LocationProvider

public static final int OUT_OF_SERVICE = 0;
public static final int TEMPORARILY_UNAVAILABLE = 1;
public static final int AVAILABLE = 2;

看一看<一href="http://blog.doityourselfandroid.com/2010/12/25/understanding-locationlistener-android/">Understanding在LocationListener的Andr​​oid中有关minTime行为的例子,一个场景(包括一些记录),以帮助您了解发生了什么事情。

Have a look at Understanding the LocationListener in Android for an example on the minTime behavior, and a scenario (including some logging) to help you understand what's going on.

请记住,调整的minTime和minDistance依旧参数对LocationManager,并在GPS状态更新行动将允许您微调您的用户的位置发展。

Keep in mind that tweaking the minTime and minDistance parameters on the LocationManager, and acting upon GPS status updates will allow you to fine-tune your user location development.

这篇关于在Android的requestLocationUpdates区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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