Android的问题,找出如何近期最新的GPS定位 [英] Android problem finding out how recent latest GPS fix is

查看:145
本文介绍了Android的问题,找出如何近期最新的GPS定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用LocationListener的跟踪当前位置。只要GPS提供商正在提供定期修复了这个效果很好。不过,我想我的应用程序,以提醒用户如果该位置已不再是可靠的,因为修复不再是当前。所以我使用了一个timeCheckHandler调用getLastKnownLocation每隔几秒钟。

My app uses LocationListener to keep track of the current location. So long as the GPS Provider is providing regular fixes this works well. However, I want my app to alert the user if the location is no longer reliable because the fix is no longer current. I have therefore used a timeCheckHandler to call getLastKnownLocation every few seconds.

我的问题是,即使当正在频繁接收准确修复通过施加的getTime(),以由getLastKnownLocation返回的位置返回的时间通常早于)由System.currentTimeMillis的(返回的当前时间,经常约20秒。

My problem is that even when accurate fixes are being received frequently the time returned by applying getTime() to the location returned by getLastKnownLocation is generally older than the current time returned by System.currentTimeMillis(), often by about 20 seconds.

我已经进一步增加code到onLocationChanged(arg0中)来记录修复(arg0.getTime())和当前时间的时间研究这个问题(System.currentTimeMillis的())。我再次看到了约20秒的差异。

I have investigated the problem further by adding code to onLocationChanged(arg0) to log the time of the fix (arg0.getTime()) and the current time (System.currentTimeMillis()). Again I see a difference of about 20 seconds.

在code当前内容如下:

The code currently reads as follows:

    public void onLocationChanged(Location arg0) {
    mapview.handleLocationChanged(mapview, arg0.getLatitude(), arg0.getLongitude(), arg0.getBearing(), arg0.getAccuracy(), "GPS fix");
    addDebugNote("Fix received at time: "+Long.toString(arg0.getTime()/1000)+" Now: "+Long.toString((System.currentTimeMillis())/1000));
}

和典型输出到我的调试文件内容如下:

and typical output to my Debug file reads:

Fix received at time: 1292091908 Now: 1292091928

为什么我要看到的修复时间和当前系统时间之间的区别是什么?

Why should I be seeing this difference between the fix time and the current system time?

我必须承认,大约20秒的差别是正常的吗?

Do I have to accept that a difference of around 20 seconds is normal?

推荐答案

GPS定位时间一到你的网络供应商的时间/设备时间独立完成。 System.currentTimeMillis的()会给你的设备上设置设备的时间。

GPS location time comes independently of your network provider time/device time. System.currentTimeMillis() will give you device time set on your device.

如果你想知道如何近期的一点是,您可以:

If you want to know how recent the point is you can:

  1. 同步均由只要你第一次GPS位置更新以两者的区别在code在应用程序启动的时间(全球定位系统和设备)。在那一瞬间,查询设备的时间,看看有什么在两者的差异。保存在变量这种差异。

  1. Synchronize both the times ( GPS and device ) in your code at application start by taking the difference between both as soon as you get first GPS location update. At that instant query device time and see what's the difference in both. Save this difference in variable.

使用这个作为一个修正系数在后续的位置更新要知道根据你所需要的参考框架上的确切时间。 (设备时间或GPS)

Use this as a correction factor in subsequent location updates to know the exact time based on the reference frame you need. ( Device time or GPS)

此外,我已经发现,使用网络位置提供你可能只能得到设备的时间。所以,如果你正在听来自两个更新(GPS和网络),你可能还需要区分这一点使用location_obj.getProvider(),并过滤掉GPS提供商。

Also I had found that using NETWORK as location provider you may get device time only. So if you are listening on updates from both ( GPS and network ) , you may also need to distinguish this using location_obj.getProvider() and filter out GPS provider.

这篇关于Android的问题,找出如何近期最新的GPS定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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