如何使用GPS即时读取位置 [英] How to make an immediate reading location using GPS

查看:68
本文介绍了如何使用GPS即时读取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Codenameone应用程序,在某些情况下需要对位置进行测量,并且需要(在时间上)立即读取。

I wrote a "Codenameone App" that needs to make Location's measures in some situations and it needs to read immediately (at time).

要实现此目标,我正在使用Display对象中的方法 getLocationSync(long timeout = 10000)。该代码是这样的:

To accomplish this goal, I'm using method "getLocationSync(long timeout=10000)" from Display object. The code is something like that:

Location loc = LocationManager
                            .getLocationManager()
                                  .getCurrentLocationSync(10000);

此方法的JavaDoc说它会立即执行测量并建议:
注意他的方法将一直阻塞直到返回结果,所以您可能要在运行时使用InfiniteProgress之类的东西。

The JavaDoc of this method says it executes a measure at moment and advises: "Notice that his method will block until a result is returned so you might want to use something like InfiniteProgress while this is running"

您可以看到,我用10调用了该方法

As you can see, I called the method with 10 seconds for timeout.

在实践中,我得到一个Location对象作为响应,但是返回的度量不是(在时间上的)立即度量。这种方法会重复一段时间(大约4或5分钟),即使我在这4分钟内改变了电话位置的时间也是如此。

Well, in practice, I get a Location object as response, but the measure returned isn't an immediate measure (at time). This method repeats the same result for a while ( about 4 or 5 minutes), even when I change the phone location significantly during those 4 minutes.

我注意到的另一件事,多数情况下,我将 InfiniteProgress称为 getCurrentLocationSync。通话很快返回。

Another thing I noticed, Most of the times I call "getCurrentLocationSync" the "InfiniteProgress" doesn't appear. The call returns quickly.

我做错了吗?
我需要怎么做才能真正获得所需的位置度量?

Am I doing something wrong? What do I need to do to get a real measure of location as I need?

推荐答案

getCurrentLocationSync 等待一个存在的位置,该位置与纯GPS模式更相关,而与现代混合位置API(如在iOS / Android中实现的位置)不相关。

The getCurrentLocationSync waits the a location to exist which is more relevant for pure GPS modes but not as relevant in modern hybrid location API's such as those implemented in iOS/Android.

默认情况下,iOS和Android都使用混合位置API,这意味着设备将结合使用wifi,手机数据和GPS来为您提供更准确,更即时的位置。即使在使用GPS的情况下,也无法知道确切的设备位置,这是有问题的,因为位置在相对较大的误差范围内,并且大多数情况下,只有在设备开始移动后才能更准确地计算出位置。

Both iOS and Android use a hybrid location API by default which means the device will use a combination of wifi, cell data and GPS to give you a location that's both more accurate and instant. It's problematic to know the exact device location even with GPS as location is within a relatively large margin of error and can mostly be calculated more accurately only once the device starts moving.

这篇关于如何使用GPS即时读取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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