Android:从精细到粗糙的 GPS 回退

Android: GPS fallback from fine to coarse(Android:从精细到粗糙的 GPS 回退)
本文介绍了Android:从精细到粗糙的 GPS 回退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

有谁知道我如何在没有修复时获取粗略的 GPS 坐标,而在修复时获取精细的 GPS 坐标?

Does anyone know how I can get coarse GPS coordinates when I don't have a fix and get fine GPS coordinates when I have a fix?

我尝试在谷歌上搜索一些示例代码,但无济于事.

I've tried googling for some sample code to no avail.

我确实找到了这个:http://www.android10.org/index.php/articleslocationmaps/226-android-location-providers-gps-network-passive

但我不知道如何实现回退到粗略/升级到精细.

But I don't know how to implement the fallback to coarse/upgrade to fine.

我希望有人可以提供帮助.提前致谢,

I hope someone can help. Thanks in advance,

推荐答案

您可以在 文档.基本思想是您可以侦听来自不同提供者的更新.收到新位置后,将其与之前存储的位置进行比较(上面的链接中提供了示例函数).

You can find an excellent introduction to the subject in the documentation. The basic idea is that you enable listening for updates from different providers. When a new location is received, you compare it to the previous stored location (a sample function is provided in the above link).

位置对象有一个 getAccuracy,您可以使用它来衡量其准确性.您还应该设置一个计时器,以便您知道位置提供商提供更新后经过了多长时间.如果 GPS 提供商为您提供更新后超过两分钟,则开始侦听网络更新.在侦听网络更新时,如果 GPS 为您提供了新的更新,则切换到正确的位置.

A location object has an getAccuracy that you can use to measure its accuracy. You should also set up a timer so that you know how long has passed after a location provider has provided an update. If more than two minutes have passed after GPS provider has given you an update, then start listening for network updates. While listening for network updates, if GPS gives you a new update, then switch to fine location.

这篇关于Android:从精细到粗糙的 GPS 回退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)