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>

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

        How long ago was the last known location recorded?(最后一个已知位置是多久前记录的?)

      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.

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                      <tbody id='aCvZH'></tbody>
                    • <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>