简体   繁体   English

如何定期从GPS获取准确的位置

[英]How to get accurate position from GPS periodically

In application I need to get geo position of phone every x minutes (for now it's 5min and 50m), in such a way that phone doesn't discharge during day. 在应用程序中,我需要每x分钟获取一次电话的地理位置(目前为5分钟和50m),以使电话不会在白天放电。 The accuracy of position must be at least 40m. 位置精度必须至少为40m。 By now I have listeners for gps and network. 现在,我已经有了用于GPS和网络的监听器。 The problem lies in the fact that the data I can receive sometimes is totally wrong (depends on phone) - new position can be even 200m from my real position and with 40m accuracy; 问题在于,有时我收到的数据是完全错误的(取决于电话)-新位置甚至可能离我的实际位置200m且精度为40m。 next point can be the same but in opposite direction. 下一个点可以相同,但方向相反。 For my app it's fatally. 对于我的应用程序,这是致命的。 So the question is next: Is there any way to get more accuracy data but not very often? 所以接下来的问题是:有没有办法获得更多准确度数据,但不是很经常?

Update 1: to show the problem in action: 更新1:显示实际问题:

在此处输入图片说明

(The phone is lying in the fixed position) (电话位于固定位置)

To get more accurate location make sure you're using the ACCESS_FINE_LOCATION permission in your manifest. 为了获得更准确的位置,请确保您在清单中使用了ACCESS_FINE_LOCATION权限。 To prevent higher battery usage, you can use setInterval and setFastestInterval on your LocationRequest object. 为了防止更高的电池使用量,可以在LocationRequest对象上使用setInterval和setFastestInterval。 Longer intervals mean less battery usage by your app. 间隔时间越长,意味着应用程序的电池消耗越少。

You should not be accessing the gps and network directly, you should be using LocationManager and using ACCURACY_FINE in your Criteria . 您不应直接访问gps和网络,而应使用LocationManager并在Criteria使用ACCURACY_FINE This will help conserve battery life, and avoid issues with phones where the gps may have been disabled. 这将有助于节省电池寿命,并避免可能禁用了gps的手机出现问题。 There's more detail on that here . 还有对更详细的在这里

As far as the accuracy of your location, you can use Location 's getAccuracy method to get Android's estimate of how accurate a measurement is. 至于位置的准确性,您可以使用LocationgetAccuracy方法来获取Android对测量精度的估计。 If it doesn't fit your criteria, discard it and poll again. 如果不符合您的条件,则将其丢弃并再次轮询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM