久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      <bdo id='rKara'></bdo><ul id='rKara'></ul>
  • <legend id='rKara'><style id='rKara'><dir id='rKara'><q id='rKara'></q></dir></style></legend>

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

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

        Android - 可靠地獲取當(dāng)前位置

        Android - Reliably getting the current location(Android - 可靠地獲取當(dāng)前位置)
        <tfoot id='YIt4i'></tfoot>
          <bdo id='YIt4i'></bdo><ul id='YIt4i'></ul>
            <tbody id='YIt4i'></tbody>

            1. <legend id='YIt4i'><style id='YIt4i'><dir id='YIt4i'><q id='YIt4i'></q></dir></style></legend>

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

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

                  本文介紹了Android - 可靠地獲取當(dāng)前位置的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我的應(yīng)用會(huì)在特定時(shí)間檢查用戶是否在給定位置.我使用警報(bào)管理器來啟動(dòng)進(jìn)行此調(diào)用的服務(wù):

                  My app checks at a specific time whether a user is at a given location. I use the alarm manager to start a service that makes this call:

                  locationManager.requestLocationUpdates(bestProvider, 0, 0, listener);
                  

                  并且還檢查:

                   locationManager.getLastKnownLocation(bestProvider);
                  

                  但我在真實(shí)設(shè)備上運(yùn)行時(shí)遇到問題.一方面,getLastKnownLocation 很可能是 GPS 的最后一個(gè)位置,它可能在任何地方(即,它可能距離用戶當(dāng)前位置數(shù)英里).所以我會(huì)等待 requestLocationUpdates 回調(diào),如果它們?cè)趦煞昼妰?nèi)不存在,請(qǐng)移除偵聽器并放棄,對(duì)嗎?

                  But I'm having problems when running on a real device. For one thing, getLastKnownLocation is most likely the last place the GPS was on, which could be anywhere (i.e., it could be miles from the user's current location). So I'll just wait for requestLocationUpdates callbacks, and if they aren't there within two minutes, remove the listener and give up, right?

                  錯(cuò)了,因?yàn)槿绻脩舻奈恢靡呀?jīng)穩(wěn)定(即他們最近使用了 GPS 并且沒有移動(dòng)),那么我的監(jiān)聽器將永遠(yuǎn)不會(huì)被調(diào)用,因?yàn)槲恢貌粫?huì)改變.但是 GPS 會(huì)一直運(yùn)行,直到我的監(jiān)聽器被移除,耗盡電池...

                  Wrong, because if the user's location is already stable (i.e., they've used GPS recently and haven't moved) then my listener will never be called because the location doesn't change. But the GPS will run until my listener is removed, draining the battery...

                  在不將舊位置誤認(rèn)為當(dāng)前位置的情況下,獲取當(dāng)前位置的正確方法是什么?我不介意等幾分鐘.

                  What is the right way to get the current location without mistaking an old location for the current location? I don't mind waiting a few minutes.

                  我可能錯(cuò)了沒有調(diào)用聽眾,這可能比我想象的要長(zhǎng)一點(diǎn)......很難說.我仍然希望得到一個(gè)明確的答案.

                  It's possible that I'm wrong about the listener not being called, it may just take a little longer than I thought... Hard to say. I'd appreciate a definitive answer still.

                  推薦答案

                  代碼可能是這樣的:

                  public class MyLocation {
                      Timer timer1;
                      LocationManager lm;
                  
                      public boolean getLocation(Context context)
                      {
                          lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
                          lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
                          timer1=new Timer();
                          timer1.schedule(new GetLastLocation(), 20000);
                          return true;
                      }
                  
                      LocationListener locationListenerGps = new LocationListener() {
                          public void onLocationChanged(Location location) {
                              timer1.cancel();
                              lm.removeUpdates(this);
                              //use location as it is the latest value
                          }
                          public void onProviderDisabled(String provider) {}
                          public void onProviderEnabled(String provider) {}
                          public void onStatusChanged(String provider, int status, Bundle extras) {}
                      };
                  
                      class GetLastLocation extends TimerTask {
                          @Override
                          public void run() {
                               lm.removeUpdates(locationListenerGps);
                               Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                               //use location as we have not received the new value from listener
                          }
                      }
                  }
                  

                  我們啟動(dòng)監(jiān)聽器并等待更新一段時(shí)間(在我的示例中為 20 秒).如果我們?cè)诖似陂g收到更新,我們會(huì)使用它.如果在此期間我們沒有收到更新,我們會(huì)使用 getLastKnownLocation 值并停止監(jiān)聽器.

                  We start the listener and wait for update for some time (20 seconds in my example). If we receive update during this time we use it. If we don't receive an update during this time we use getLastKnownLocation value and stop the listener.

                  您可以在此處查看我的完整代碼 在 Android 上獲取用戶當(dāng)前位置的最簡(jiǎn)單、最可靠的方法是什么?

                  You can see my complete code here What is the simplest and most robust way to get the user's current location on Android?

                  編輯(由提問者):這是大部分答案,但我的最終解決方案使用 Handler 而不是 Timer.

                  EDIT (by asker): This is most of the answer, but my final solution uses a Handler instead of a Timer.

                  這篇關(guān)于Android - 可靠地獲取當(dāng)前位置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計(jì)算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負(fù)速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)

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

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

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

                          <tbody id='GK0AK'></tbody>

                          <bdo id='GK0AK'></bdo><ul id='GK0AK'></ul>
                          • 主站蜘蛛池模板: 日本亚洲天堂 | 精品一区二区免费视频 | 国产第四页 | 国产视频一二区 | 亚洲精品黄 | 国产精品欧美在线 | av片网站 | 69视频网站 | 日韩精品国产精品 | 久久伊人国产 | 国产a精品| 国产一级特黄 | 久久久精品 | 蜜桃色一区二区三区 | 色婷婷国产 | 亚洲欧美日韩国产 | 男男成人高潮片免费网站 | 亚洲天天 | 黄视频在线播放 | 亚洲性生活片 | 五月色综合 | 黄色三级免费 | 午夜av网站 | 一级做a爱片性色毛片 | 精品视频免费在线观看 | 久草福利资源 | 亚洲精品一区二区三区精华液 | 日本一级一片免费视频 | 色视频www在线播放国产人成 | 日本免费在线观看视频 | 日韩国产一区二区 | 九九精品在线观看 | 国产欧美一区二区三区视频在线观看 | 精品第一页 | 亚洲精品久久久久avwww潮水 | 日韩精品免费观看 | 国产呦小j女精品视频 | 日本国产精品 | 中文字幕国产在线 | 国产裸体永久免费视频网站 | 久久99精品久久久久久 |