• <tfoot id='81K66'></tfoot>

        <i id='81K66'><tr id='81K66'><dt id='81K66'><q id='81K66'><span id='81K66'><b id='81K66'><form id='81K66'><ins id='81K66'></ins><ul id='81K66'></ul><sub id='81K66'></sub></form><legend id='81K66'></legend><bdo id='81K66'><pre id='81K66'><center id='81K66'></center></pre></bdo></b><th id='81K66'></th></span></q></dt></tr></i><div id='81K66'><tfoot id='81K66'></tfoot><dl id='81K66'><fieldset id='81K66'></fieldset></dl></div>
          <bdo id='81K66'></bdo><ul id='81K66'></ul>
        <legend id='81K66'><style id='81K66'><dir id='81K66'><q id='81K66'></q></dir></style></legend>

        <small id='81K66'></small><noframes id='81K66'>

        如何获取未过期的位置?

        时间:2023-09-01

          <legend id='z7rlL'><style id='z7rlL'><dir id='z7rlL'><q id='z7rlL'></q></dir></style></legend>

          <i id='z7rlL'><tr id='z7rlL'><dt id='z7rlL'><q id='z7rlL'><span id='z7rlL'><b id='z7rlL'><form id='z7rlL'><ins id='z7rlL'></ins><ul id='z7rlL'></ul><sub id='z7rlL'></sub></form><legend id='z7rlL'></legend><bdo id='z7rlL'><pre id='z7rlL'><center id='z7rlL'></center></pre></bdo></b><th id='z7rlL'></th></span></q></dt></tr></i><div id='z7rlL'><tfoot id='z7rlL'></tfoot><dl id='z7rlL'><fieldset id='z7rlL'></fieldset></dl></div>
            <tbody id='z7rlL'></tbody>

            <tfoot id='z7rlL'></tfoot>

              <small id='z7rlL'></small><noframes id='z7rlL'>

                <bdo id='z7rlL'></bdo><ul id='z7rlL'></ul>
                • 本文介绍了如何获取未过期的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  启用 GPS 后,需要一些时间才能准备好 GPS.所以使用这个代码可能会得到一个过时的位置:位置 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);我无法使用已过期的位置.如何获得我需要的位置?

                  After GPS is enabled, it will take some time before the GPS is ready. So use this code may get a location that is out of date: location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); I can't use the location that is out of date. How can I get the location that I need?

                  这是一个类似的问题:Android:getLastKnownLocation 过期 - 如何强制位置刷新?

                  从中,我可以使用 LocationListener 获取更新的位置,该位置应该不会过时.这是正确的.但是我该如何处理这种情况:

                  From it, I can use LocationListener to get the updated location, which should be not out of date. It's correct. But how can I handle this case:

                  我已经启用了 GPS,然后启动我的应用程序.如果我呆在一个地方不动,那么 onLocationChanged() 将不会被调用.所以不能用这个方法来判断getLastKnownLocation()的返回值是不是过期了?

                  I have already enabled GPS, and then start my app. If I stay at one place and don't move, then onLocationChanged() won't be called. So I can't use this method to judge whether the return value of getLastKnownLocation() is not out-of-date?

                  有什么想法吗?

                  推荐答案

                  如何获取未过期的位置?

                  How to get location that isn't out of date?

                  您调用 requestLocationUpdates() 的 minTime 为 1000 毫秒,对于 onLocationChanged() 中的每个 Location,您调用 getAccuracy().如果您可以接受准确度,请调用 removeUpdates().

                  You call requestLocationUpdates() with the minTime of 1000 ms, for every Location in onLocationChanged(), you call getAccuracy(). If the accuracy is acceptable for you, call removeUpdates().

                  所以我不能用这个方法来判断getLastKnownLocation()的返回值是否过时

                  So I can't use this method to judge whether the return value of getLastKnownLocation() is not out-of-date

                  我认为它返回的 Location 对象将包含一个 时间戳.您可以为现在与位置的 getTime()

                  I think the Location object that it returns will contain a time stamp. You can set a tolerance for the time difference between now and the Location's getTime()

                  这篇关于如何获取未过期的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                • <small id='p4ay6'></small><noframes id='p4ay6'>

                    <tbody id='p4ay6'></tbody>
                  <i id='p4ay6'><tr id='p4ay6'><dt id='p4ay6'><q id='p4ay6'><span id='p4ay6'><b id='p4ay6'><form id='p4ay6'><ins id='p4ay6'></ins><ul id='p4ay6'></ul><sub id='p4ay6'></sub></form><legend id='p4ay6'></legend><bdo id='p4ay6'><pre id='p4ay6'><center id='p4ay6'></center></pre></bdo></b><th id='p4ay6'></th></span></q></dt></tr></i><div id='p4ay6'><tfoot id='p4ay6'></tfoot><dl id='p4ay6'><fieldset id='p4ay6'></fieldset></dl></div>
                    <bdo id='p4ay6'></bdo><ul id='p4ay6'></ul>
                      <legend id='p4ay6'><style id='p4ay6'><dir id='p4ay6'><q id='p4ay6'></q></dir></style></legend>
                    1. <tfoot id='p4ay6'></tfoot>