How to make an immediate reading location using GPS

雨燕双飞 提交于 2020-01-14 04:17:50

问题


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

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

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"

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

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.

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/36577986/how-to-make-an-immediate-reading-location-using-gps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!