国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

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

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

開(kāi)通VIP
GPS開(kāi)發(fā)常用方法 和用Criteria確定android location provid...

GPS開(kāi)發(fā)常用方法 和用Criteria確定android location providerGPS開(kāi)發(fā)常用方法

取得LocationProvider

Java代碼
  1. public void getLocationProvider()    
  2.   {    
  3.     try    
  4.     {    
  5.       Criteria mCriteria01 = new Criteria();    
  6.       mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);    
  7.       mCriteria01.setAltitudeRequired(false);    
  8.       mCriteria01.setBearingRequired(false);    
  9.       mCriteria01.setCostAllowed(true);    
  10.       mCriteria01.setPowerRequirement(Criteria.POWER_LOW);    
  11.       strLocationProvider =     
  12.       mLocationManager01.getBestProvider(mCriteria01, true);    
  13.           
  14.       mLocation01 = mLocationManager01.getLastKnownLocation    
  15.       (strLocationProvider);    
  16.     }    
  17.     catch(Exception e)    
  18.     {    
  19.       mTextView01.setText(e.toString());    
  20.       e.printStackTrace();    
  21.     }    
  22.   }   
Java代碼
  1. public void getLocationProvider()    
  2.   {    
  3.     try    
  4.     {    
  5.       Criteria mCriteria01 = new Criteria();    
  6.       mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);    
  7.       mCriteria01.setAltitudeRequired(false);    
  8.       mCriteria01.setBearingRequired(false);    
  9.       mCriteria01.setCostAllowed(true);    
  10.       mCriteria01.setPowerRequirement(Criteria.POWER_LOW);    
  11.       strLocationProvider =     
  12.       mLocationManager01.getBestProvider(mCriteria01, true);    
  13.           
  14.       mLocation01 = mLocationManager01.getLastKnownLocation    
  15.       (strLocationProvider);    
  16.     }    
  17.     catch(Exception e)    
  18.     {    
  19.       mTextView01.setText(e.toString());    
  20.       e.printStackTrace();    
  21.     }    
  22.   }   

獲取經(jīng)緯度,并返回GeoPoint對(duì)象
Java代碼
  1. private GeoPoint getGeoByLocation(Location location)   
  2.   {   
  3.     GeoPoint gp = null;   
  4.     try  
  5.     {   
  6.       /* 當(dāng)Location存在 */  
  7.       if (location != null)   
  8.       {   
  9.         double geoLatitude = location.getLatitude()*1E6;   
  10.         double geoLongitude = location.getLongitude()*1E6;   
  11.         gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);   
  12.       }   
  13.     }   
  14.     catch(Exception e)   
  15.     {   
  16.       e.printStackTrace();   
  17.     }   
  18.     return gp;   
  19.   }  
Java代碼
  1. private GeoPoint getGeoByLocation(Location location)   
  2.   {   
  3.     GeoPoint gp = null;   
  4.     try  
  5.     {   
  6.       /* 當(dāng)Location存在 */  
  7.       if (location != null)   
  8.       {   
  9.         double geoLatitude = location.getLatitude()*1E6;   
  10.         double geoLongitude = location.getLongitude()*1E6;   
  11.         gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);   
  12.       }   
  13.     }   
  14.     catch(Exception e)   
  15.     {   
  16.       e.printStackTrace();   
  17.     }   
  18.     return gp;   
  19.   }  

將經(jīng)緯度轉(zhuǎn)換成實(shí)際屏幕坐標(biāo)
Java代碼
  1. Point myScreenCoords = new Point();   
  2. GeoPoint tmpGeoPoint = new GeoPoint((int)(mLocation.getLatitude()*1E6),(int)(mLocation.getLongitude()*1E6));   
  3. mapView.getProjection().toPixels(tmpGeoPoint, myScreenCoords);  
Java代碼
  1. Point myScreenCoords = new Point();   
  2. GeoPoint tmpGeoPoint = new GeoPoint((int)(mLocation.getLatitude()*1E6),(int)(mLocation.getLongitude()*1E6));   
  3. mapView.getProjection().toPixels(tmpGeoPoint, myScreenCoords);  


點(diǎn)擊MapView任意一點(diǎn)獲得坐標(biāo)
Java代碼
  1. @Override    
  2. public boolean onTouchEvent(MotionEvent ev) {    
  3.     int actionType = ev.getAction();    
  4.     switch (actionType) {    
  5.     case MotionEvent.ACTION_UP:         
  6.             Projection proj = mapView.getProjection();    
  7.             GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());     
  8.             String sirina=Double.toString(loc.getLongitudeE6()/1000000);    
  9.             String dolzina=Double.toString(loc.getLatitudeE6()/1000000);    
  10.        
  11.     }    
  12.     
  13.     return false;   
  14. }  
Java代碼
  1. @Override    
  2. public boolean onTouchEvent(MotionEvent ev) {    
  3.     int actionType = ev.getAction();    
  4.     switch (actionType) {    
  5.     case MotionEvent.ACTION_UP:         
  6.             Projection proj = mapView.getProjection();    
  7.             GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());     
  8.             String sirina=Double.toString(loc.getLongitudeE6()/1000000);    
  9.             String dolzina=Double.toString(loc.getLatitudeE6()/1000000);    
  10.        
  11.     }    
  12.     
  13.     return false;   
  14. }  



經(jīng)緯度改變來(lái)刷新地圖
Java代碼
  1. public void refreshMapView()    
  2. {    
  3.   GeoPoint p = new GeoPoint((int)(dLat* 1E6), (int)(dLng* 1E6));    
  4.   mMapView01.displayZoomControls(true);   
  5.   /* 將Map的中點(diǎn)移至GeoPoint */  
  6.   mMapController01.animateTo(p);    
  7.   mMapController01.setZoom(intZoomLevel);    
  8. }   
Java代碼
  1. public void refreshMapView()    
  2. {    
  3.   GeoPoint p = new GeoPoint((int)(dLat* 1E6), (int)(dLng* 1E6));    
  4.   mMapView01.displayZoomControls(true);   
  5.   /* 將Map的中點(diǎn)移至GeoPoint */  
  6.   mMapController01.animateTo(p);    
  7.   mMapController01.setZoom(intZoomLevel);    
  8. }   


根據(jù)當(dāng)前的經(jīng)緯度,獲取相關(guān)的一些地址信息
Java代碼
  1. /* 創(chuàng)建Geocoder對(duì)象 */  
  2.         //根據(jù)地理環(huán)境來(lái)確定編碼   
  3.         //注意這個(gè)Locale是java.util.Locale包的類(lèi),獲取當(dāng)前系統(tǒng)設(shè)定的語(yǔ)言   
  4.         Geocoder gc = new Geocoder   
  5.         (EX09_05.this, Locale.getDefault());   
  6.            
  7.         /* 取出地理坐標(biāo)經(jīng)緯度 */  
  8.         double geoLatitude = (int)gp.getLatitudeE6()/1E6;   
  9.         double geoLongitude = (int)gp.getLongitudeE6()/1E6;   
  10.            
  11.         /* 自經(jīng)緯度取得地址(可能有多行地址) */  
  12.         List<Address> lstAddress =    
  13.         gc.getFromLocation(geoLatitude, geoLongitude, 1);   
  14.            
  15.         StringBuilder sb = new StringBuilder();   
  16.            
  17.         /* 判斷地址是否為多行 */  
  18.         if (lstAddress.size() > 0)   
  19.         {   
  20.           Address adsLocation = lstAddress.get(0);   
  21.   
  22.           for(int i=0;i<adsLocation.getMaxAddressLineIndex();i++)   
  23.           {   
  24.             sb.append(adsLocation.getAddressLine(i)).append("\n");   
  25.           }   
  26.           sb.append(adsLocation.getLocality()).append("\n");   
  27.           sb.append(adsLocation.getPostalCode()).append("\n");   
  28.           sb.append(adsLocation.getCountryName());   
  29.         }   
  30.           
Java代碼
  1. /* 創(chuàng)建Geocoder對(duì)象 */  
  2.         //根據(jù)地理環(huán)境來(lái)確定編碼   
  3.         //注意這個(gè)Locale是java.util.Locale包的類(lèi),獲取當(dāng)前系統(tǒng)設(shè)定的語(yǔ)言   
  4.         Geocoder gc = new Geocoder   
  5.         (EX09_05.this, Locale.getDefault());   
  6.            
  7.         /* 取出地理坐標(biāo)經(jīng)緯度 */  
  8.         double geoLatitude = (int)gp.getLatitudeE6()/1E6;   
  9.         double geoLongitude = (int)gp.getLongitudeE6()/1E6;   
  10.            
  11.         /* 自經(jīng)緯度取得地址(可能有多行地址) */  
  12.         List<Address> lstAddress =    
  13.         gc.getFromLocation(geoLatitude, geoLongitude, 1);   
  14.            
  15.         StringBuilder sb = new StringBuilder();   
  16.            
  17.         /* 判斷地址是否為多行 */  
  18.         if (lstAddress.size() > 0)   
  19.         {   
  20.           Address adsLocation = lstAddress.get(0);   
  21.   
  22.           for(int i=0;i<adsLocation.getMaxAddressLineIndex();i++)   
  23.           {   
  24.             sb.append(adsLocation.getAddressLine(i)).append("\n");   
  25.           }   
  26.           sb.append(adsLocation.getLocality()).append("\n");   
  27.           sb.append(adsLocation.getPostalCode()).append("\n");   
  28.           sb.append(adsLocation.getCountryName());   
  29.         }   
  30.           



根據(jù)輸入地址,取得其GeoPoint對(duì)象
Java代碼
  1. private GeoPoint getGeoByAddress(String strSearchAddress)    
  2. {    
  3.   GeoPoint gp = null;    
  4.   try    
  5.   {    
  6.     if(strSearchAddress!="")    
  7.     {    
  8.       Geocoder mGeocoder01 = new Geocoder    
  9.       (EX09_07.this, Locale.getDefault());    
  10.           
  11.       List<Address> lstAddress = mGeocoder01.getFromLocationName   
  12.                          (strSearchAddress, 1);   
  13.       if (!lstAddress.isEmpty())    
  14.       {    
  15.         Address adsLocation = lstAddress.get(0);    
  16.         double geoLatitude = adsLocation.getLatitude()*1E6;    
  17.         double geoLongitude = adsLocation.getLongitude()*1E6;    
  18.         gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);    
  19.       }    
  20.     }    
  21.   }    
  22.   catch (Exception e)    
  23.   {     
  24.     e.printStackTrace();     
  25.   }    
  26.   return gp;    
  27. }   
Java代碼
  1. private GeoPoint getGeoByAddress(String strSearchAddress)    
  2. {    
  3.   GeoPoint gp = null;    
  4.   try    
  5.   {    
  6.     if(strSearchAddress!="")    
  7.     {    
  8.       Geocoder mGeocoder01 = new Geocoder    
  9.       (EX09_07.this, Locale.getDefault());    
  10.           
  11.       List<Address> lstAddress = mGeocoder01.getFromLocationName   
  12.                          (strSearchAddress, 1);   
  13.       if (!lstAddress.isEmpty())    
  14.       {    
  15.         Address adsLocation = lstAddress.get(0);    
  16.         double geoLatitude = adsLocation.getLatitude()*1E6;    
  17.         double geoLongitude = adsLocation.getLongitude()*1E6;    
  18.         gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);    
  19.       }    
  20.     }    
  21.   }    
  22.   catch (Exception e)    
  23.   {     
  24.     e.printStackTrace();     
  25.   }    
  26.   return gp;    
  27. }   


地圖放大縮小按鈕
Java代碼
  1. /* 放大Map的Button */  
  2.    mButton02 = (Button)findViewById(R.id.myButton2);    
  3.    mButton02.setOnClickListener(new Button.OnClickListener()    
  4.    {    
  5.        
  6.      public void onClick(View v)    
  7.      {    
  8.        intZoomLevel++;    
  9.        if(intZoomLevel>mMapView01.getMaxZoomLevel())    
  10.        {    
  11.          intZoomLevel = mMapView01.getMaxZoomLevel();    
  12.        }    
  13.        mMapController01.setZoom(intZoomLevel);    
  14.      }    
  15.    });    
  16.        
  17.    /* 縮小Map的Button */  
  18.    mButton03 = (Button)findViewById(R.id.myButton3);    
  19.    mButton03.setOnClickListener(new Button.OnClickListener()    
  20.    {    
  21.          
  22.      public void onClick(View v)    
  23.      {    
  24.        intZoomLevel--;    
  25.        if(intZoomLevel<1)    
  26.        {    
  27.          intZoomLevel = 1;    
  28.        }    
  29.        mMapController01.setZoom(intZoomLevel);    
  30.      }    
  31.    });  
Java代碼
  1. /* 放大Map的Button */  
  2.    mButton02 = (Button)findViewById(R.id.myButton2);    
  3.    mButton02.setOnClickListener(new Button.OnClickListener()    
  4.    {    
  5.        
  6.      public void onClick(View v)    
  7.      {    
  8.        intZoomLevel++;    
  9.        if(intZoomLevel>mMapView01.getMaxZoomLevel())    
  10.        {    
  11.          intZoomLevel = mMapView01.getMaxZoomLevel();    
  12.        }    
  13.        mMapController01.setZoom(intZoomLevel);    
  14.      }    
  15.    });    
  16.        
  17.    /* 縮小Map的Button */  
  18.    mButton03 = (Button)findViewById(R.id.myButton3);    
  19.    mButton03.setOnClickListener(new Button.OnClickListener()    
  20.    {    
  21.          
  22.      public void onClick(View v)    
  23.      {    
  24.        intZoomLevel--;    
  25.        if(intZoomLevel<1)    
  26.        {    
  27.          intZoomLevel = 1;    
  28.        }    
  29.        mMapController01.setZoom(intZoomLevel);    
  30.      }    
  31.    });  


以下文章轉(zhuǎn)載:http://marshal.easymorse.com/archives/2528
android location provider有兩個(gè):

    * LocationManager.GPS_PROVIDER:GPS,精度比較高,但是慢而且消耗電力,而且可能因?yàn)樘鞖庠蚧蛘哒系K物而無(wú)法獲取衛(wèi)星信息,另外設(shè)備可能沒(méi)有GPS模塊;
    * LocationManager.NETWORK_PROVIDER:通過(guò)網(wǎng)絡(luò)獲取定位信息,精度低,耗電少,獲取信息速度較快,不依賴(lài)GPS模塊。

為了程序的通用性,希望動(dòng)態(tài)選擇location provider。對(duì)android通過(guò)Location API顯示地址信息做了個(gè)別改動(dòng),可以看到使用了gps定位,精度較高:



這里使用到了Criteria,可根據(jù)當(dāng)前設(shè)備情況自動(dòng)選擇哪種location provider。見(jiàn)
Java代碼
  1. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
  2.   
  3. Criteria criteria = new Criteria();   
  4. criteria.setAccuracy(Criteria.ACCURACY_FINE);// 設(shè)置為最大精度   
  5. criteria.setAltitudeRequired(false);//不要求海拔信息   
  6. criteria.setBearingRequired(false);// 不要求方位信息   
  7. criteria.setCostAllowed(true);//是否允許付費(fèi)   
  8. criteria.setPowerRequirement(Criteria.POWER_LOW);// 對(duì)電量的要求   
  9.   
  10. location = locationManager   
  11.         .getLastKnownLocation(locationManager.getBestProvider(criteria, true));  
Java代碼
  1. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
  2.   
  3. Criteria criteria = new Criteria();   
  4. criteria.setAccuracy(Criteria.ACCURACY_FINE);// 設(shè)置為最大精度   
  5. criteria.setAltitudeRequired(false);//不要求海拔信息   
  6. criteria.setBearingRequired(false);// 不要求方位信息   
  7. criteria.setCostAllowed(true);//是否允許付費(fèi)   
  8. criteria.setPowerRequirement(Criteria.POWER_LOW);// 對(duì)電量的要求   
  9.   
  10. location = locationManager   
  11.         .getLastKnownLocation(locationManager.getBestProvider(criteria, true));  

原來(lái)的寫(xiě)法很簡(jiǎn)單:
Java代碼
  1. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
  2.   
  3. location=locationManager.getLastKnownLocation(LocationManager.NETWORK  
Java代碼
  1. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
  2.   
  3. location=locationManager.getLastKnownLocation(LocationManager.NETWORK)  
Java代碼
  1.   
Java代碼
  1.   
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android實(shí)現(xiàn)基站定位配合GPS定位的方法
android定位和地圖開(kāi)發(fā)實(shí)例
android中模擬器中實(shí)現(xiàn)GPS坐標(biāo)改變
Excel VBA解讀(52):自動(dòng)篩選——AutoFilter方法
Android?成功?使用GPS獲取當(dāng)前地理位置(解決getLastKnownLocati...
java – 從單獨(dú)的線(xiàn)程發(fā)出Toast消息
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服