欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Android?成功?使用GPS獲取當前地理位置(解決getLastKnownLocati...
自本篇博客發(fā)布以來(lái),收到了很多同行的郵件,大部分都是給我要MapUtils.java文件,或者要關(guān)于定位的Demo。以后也省的大家麻煩了,我直接把Demo掛到我的115網(wǎng)盤(pán)上去,大家可以去那里下載。不過(guò)好像你得先注冊才行,但我又沒(méi)更好的存儲方式,只能先存在那里了(注意該Demo無(wú)法運行,因為我是從項目中抽出來(lái)的,但我能保證,該Demo包含了我所有的定位代碼,自己調試吧,你懂的)...
  360云盤(pán)地址:http://yunpan.cn/QWPKiTi7kbBxM


這兩天可憋壞我了,一直愁沒(méi)什么題材可以充實(shí)我的博客,正巧最近遇到一個(gè)比較棘手的問(wèn)題:
使用GPS定位無(wú)法獲取當前的地理位置,即getLastKnownLocation方法始終返回null。

后來(lái)一篇博文 getLastKnownLocation()返回null的解決 幫了我大忙,在此對該博客作者表示感謝,但是有幾點(diǎn)需要注意的,我覺(jué)得有必要補充一下,否則看了這篇博文也還是得不到當前的地理位置。

第一:當使用GPS定位時(shí),最好不要使用getLastKnownLocation方法獲得當前位置對象Location,因為該對象可以在onLocationChanged的參數中由系統給予(根據文檔,getLastKnownLocation有2方面功能:1. 獲取當前地理位置2.如果當前位置定位不成功,則可以用此方法獲取緩存中的上一次打開(kāi)地圖時(shí)定位的地理位置)。這樣就避免了空指針異常。而且更重要的是GPS定位不是一下子就能定位成功的,在90%以上的情況下,getLastKnownLocation返回null

第二:LocationListener最好在A(yíng)ctivity的onCreate()方法中進(jìn)行實(shí)例化
     實(shí)現系統的回調方法:
       onLocationChanged(finalLocation loc)
       onProviderDisabled(final Strings)
       onProviderEnabled(final Strings)
       onStatusChanged(final String s,final int i, final Bundle b)

第三:requestLocationUpdates必須要在onResume()中進(jìn)行注冊監聽(tīng). 且在onPause()中進(jìn)行反注  冊。

第四:測試GPS是否定位成功,去一個(gè)空曠的地方去,不要有遮擋。這點(diǎn)非常重要,不然,你永遠也不知道自己GPS定位是否成功。

以下是我用GPS成功獲取當前地理位置的例子。希望能夠幫助大家擺脫GPS定位的陰霾。

@Override
public void onCreate(final Bundle icicle) {
     super.onCreate(icicle);
     this.setContentView(R.layout.activity_mapview);

     mBtnDone =(Button) findViewById(R.id.btn_done);
     mBtnDone.setOnClickListener(this);

     mapView = (MapView) findViewById(R.id.map_view);
     mapView.setBuiltInZoomControls(true);
     mapController = mapView.getController();
     mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    mDefaultMarker =getResources().getDrawable(R.drawable.map_redpin);
    mDefaultMarker.setBounds(0, 0,mDefaultMarker.getIntrinsicWidth(),
    mDefaultMarker.getIntrinsicHeight());

     mBuoyOverlay = new BuoyItemizedOverlay(mDefaultMarker, this);
     initDensityDpi();
     mZoomLevel = mapView.getMaxZoomLevel() - 1;
/LocationListener最好在A(yíng)ctivity的onCreate()方法中進(jìn)行實(shí)例化,當GPS獲得Location時(shí),會(huì )自      動(dòng)調用onLocationChanged方法.

     mLocationListener = new LocationListener() {
         @Override
         public voidonLocationChanged(final Location loc) {
         LogHelper.i(TAG,"onLocationChanged. loc: " + loc);
         if (loc != null) {
                LogHelper.i(TAG, "onLocationChanged. latitude:"
                        + loc.getLatitude() + " ,longtitude: ".getLongitude());
                GeoPoint geoPoint =MapUtils.getGeoPoint(loc);
                mapController.animateTo(geoPoint);
                initBuoyOverlayItems(loc);
        } else {
           Toast( MapViewActivity.this, "Yourcurrent location is temporarily unavailable.",
              Toast.LENGTH_SHORT).show();
        }
     }

      // 當系統Setting -> Location& Security -> Use wirelessnetworks取消勾選,Use GPS                 satellites取消勾選時(shí)調用
      public void onProviderDisabled(final String s){
              LogHelper.i(TAG, "onProviderDisabled. ");
      }
                    
       // 當系統Setting -> Location& Security -> Use wirelessnetworks勾選,Use GPS satellites勾         選時(shí)調用
       public void onProviderEnabled(final String s){
            LogHelper.i(TAG, "onProviderEnabled. ");
       }

       public void onStatusChanged(final String s,final int i, final Bundle b) {
            LogHelper.i(TAG, "onStatusChanged. ");
       }
      };
    }

      @Override
      public void onStart() {
         super.onStart();

          mapController.setZoom(mZoomLevel);
           if(!DoSomeGoodUtils.isNetworkAvailable(this)) {
              mBtnDone.setEnabled(false);
              showDialog(DIALOG_NO_NETWORK);
          } else{
               // 判斷UseGPS satellites.是否勾選
               booleanisGpsEnabled = MapUtils.isGPSProviderAvaliable(this);
               // 判斷Usewireless networks 是否勾選
               booleanisWIFIEnabled = MapUtils.isWIFIProviderAvaliable(this);
               if(!isGpsEnabled && !isWIFIEnabled){
                   如果都沒(méi)有勾選,則彈出對話(huà)框,提示用戶(hù)勾選。
              }
              else {
                   Location lastKnownLocation =null;
                   // 如果只是Use GPSsatellites勾選,即指允許使用GPS定位
                    if(isGpsEnabled && !isWIFIEnabled){                 lastKnownLocation=mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                   mProviderName =LocationManager.GPS_PROVIDER;

                   // 如果只是Use wirelessnetworks勾選,即只允許使用網(wǎng)絡(luò )定位。
                  } else if(!isGpsEnabled&& isWIFIEnabled){
                   lastKnownLocation =   mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                   mProviderName =LocationManager.NETWORK_PROVIDER;

                    //如果二者都勾選,優(yōu)先使用GPS,因為GPS定位更精確。
                 } else if (isGpsEnabled&& isWIFIEnabled){           lastKnownLocation=mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                mProviderName =LocationManager.GPS_PROVIDER;
                if (lastKnownLocation == null) {
          lastKnownLocation=mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
             mProviderName =LocationManager.NETWORK_PROVIDER;
                }
       }
         if(!TextUtils.isEmpty(mProviderName)) {
             mLocationManager.requestLocationUpdates(
                  mProviderName, 1000, 1,mLocationListener);
           }

         //如果一下子就能定位成功,則執行以下代碼,當用網(wǎng)絡(luò )定位時(shí),大都能一次性定位成功,當用GPS時(shí),該代碼不會(huì )起太大作用。
        if (lastKnownLocation != null){
            mBtnDone.setEnabled(true);
            // 獲取當前地理位置
           GeoPoint lastKnownPoint =getLastKnownPoint(lastKnownLocation);
            // 以動(dòng)畫(huà)方式移動(dòng)到該地理位置
            mapController.animateTo(lastKnownPoint);
            // 更新浮標。該方法在這里就不公開(kāi)了。知道它的含義就行
            initBuoyOverlayItems(lastKnownLocation);
        }
      }
     }
    }

    @Override
     protected void onResume() {
          super.onResume();
          LogHelper.i(TAG, "onResume. Provider Name: " +mProviderName);
         if(!TextUtils.isEmpty(mProviderName)) {
          //當GPS定位時(shí),在這里注冊requestLocationUpdates監聽(tīng)就非常重要而且必要。
沒(méi)有這句話(huà),定位不能成功。
           mLocationManager.requestLocationUpdates(mProviderName,1000, 1,
                mLocationListener);
          }
        }

        @Override
        protected void onPause(){
         super.onPause();
          //取消注冊監聽(tīng)
          if(mLocationManager != null) {
            mLocationManager.removeUpdates(mLocationListener);
          }
     }
}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android GPS 簡(jiǎn)介
android手機定位不準的問(wèn)題
java – 從單獨的線(xiàn)程發(fā)出Toast消息
獲取地理位置信息android,Android獲取地理位置信息(GPS/NETWORK)
徹底解決Android GPS沒(méi)法定位這一頑固問(wèn)題
Android 打開(kāi) GPS 導航并獲取位置信息 - 創(chuàng )世軟件團隊 - 博客園
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久