1. <small id='yzzcx'></small><noframes id='yzzcx'>

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

          <bdo id='yzzcx'></bdo><ul id='yzzcx'></ul>
      2. <legend id='yzzcx'><style id='yzzcx'><dir id='yzzcx'><q id='yzzcx'></q></dir></style></legend>

        最后一个已知位置是多久前记录的?

        时间:2023-05-27

      3. <i id='sVZlU'><tr id='sVZlU'><dt id='sVZlU'><q id='sVZlU'><span id='sVZlU'><b id='sVZlU'><form id='sVZlU'><ins id='sVZlU'></ins><ul id='sVZlU'></ul><sub id='sVZlU'></sub></form><legend id='sVZlU'></legend><bdo id='sVZlU'><pre id='sVZlU'><center id='sVZlU'></center></pre></bdo></b><th id='sVZlU'></th></span></q></dt></tr></i><div id='sVZlU'><tfoot id='sVZlU'></tfoot><dl id='sVZlU'><fieldset id='sVZlU'></fieldset></dl></div>
        • <small id='sVZlU'></small><noframes id='sVZlU'>

            1. <legend id='sVZlU'><style id='sVZlU'><dir id='sVZlU'><q id='sVZlU'></q></dir></style></legend>
              • <tfoot id='sVZlU'></tfoot>
                  <tbody id='sVZlU'></tbody>
                  <bdo id='sVZlU'></bdo><ul id='sVZlU'></ul>

                  本文介绍了最后一个已知位置是多久前记录的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在获取我最后一次知道的位置,但我不知道距离上次更新我的位置已有多长时间.我如何才能知道距离上次更新位置已有多长时间?

                  I am getting my last known location but not how long it has been since my location was last updated. How can I find out how long it has been since the location was last updated?

                  LocationManager locationManager 
                                          = (LocationManager) getSystemService(LOCATION_SERVICE);
                  Criteria c = new Criteria();
                      c.setAccuracy(Criteria.ACCURACY_FINE);
                      c.setAccuracy(Criteria.ACCURACY_COARSE);
                      c.setAltitudeRequired(false);
                      c.setBearingRequired(false);
                      c.setCostAllowed(true);
                      c.setPowerRequirement(Criteria.POWER_HIGH);
                  String provider = locationManager.getBestProvider(c, true);
                  Location location = locationManager.getLastKnownLocation(provider);
                  

                  推荐答案

                  API 17 前后的最佳选择:

                  Best option for both pre and post API 17:

                  public int age_minutes(Location last) {
                      return age_ms(last) / (60*1000);
                  }
                  
                  public long age_ms(Location last) {
                      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
                          return age_ms_api_17(last);
                      return age_ms_api_pre_17(last);
                  }
                  
                  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
                  private long age_ms_api_17(Location last) {
                      return (SystemClock.elapsedRealtimeNanos() - last
                              .getElapsedRealtimeNanos()) / 1000000;
                  }
                  
                  private long age_ms_api_pre_17(Location last) {
                      return System.currentTimeMillis() - last.getTime();
                  }
                  

                  pre 17 不是很准确,但应该足以测试一个位置是否很旧.

                  The pre 17 is not very accurate, but should be sufficient to test if a location is very old.

                  我认为这样就可以了:

                  if (age_minutes(lastLoc) < 5) {
                     // fix is under 5 mins old, we'll use it
                  
                  } else {
                     // older than 5 mins, we'll ignore it and wait for new one
                  
                  }
                  

                  此逻辑的通常用例是应用刚刚启动时,我们需要知道我们是必须等待新位置还是在等待新位置时可以暂时使用最新位置位置.

                  The usual use case for this logic is when the app has just started and we need to know whether we must wait for a new location or can use the latest for now while we wait for a new location.

                  这篇关于最后一个已知位置是多久前记录的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在圆中寻找坐标 下一篇:将网络位置保存为 .txt 文件(不使用 GPS)

                  相关文章

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

                    <tfoot id='aCvZH'></tfoot>

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

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