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

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

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

        时间:2023-09-30

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

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

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

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

                  问题描述

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

                  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.

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

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

                  相关文章

                  最新文章

                • <tfoot id='PG4wN'></tfoot>

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