亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android編程實現(xiàn)GPS位置獲取的方法

 更新時間:2017年07月14日 10:19:30   作者:只要你能好  
這篇文章主要介紹了Android編程實現(xiàn)GPS位置獲取的方法,結(jié)合具體實例形式分析了Android針對GPS定位的常見操作技巧,需要的朋友可以參考下

本文實例講述了Android編程實現(xiàn)GPS位置獲取的方法。分享給大家供大家參考,具體如下:

public class GPSInfoService {
  private static GPSInfoService mInstance;
  private LocationManager locationManager;//定位服務(wù)
  private GPSInfoService(Context context) {
    // TODO Auto-generated constructor stub
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  }
  public static GPSInfoService getInstance(Context context){
    if(mInstance == null){
      mInstance = new GPSInfoService(context);
    }
    return mInstance;
  }
  //注冊定位監(jiān)聽
  public void registenerLocationChangeListener(){
    //得到所有的定位服務(wù)
//   List<String> providers = locationManager.getAllProviders();
//   for(String provider:providers){
//     Log.i("i", provider);
//   }
    //查詢條件
    Criteria criteria = new Criteria();
    //定位的精準(zhǔn)度
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //海拔信息是否關(guān)注
    criteria.setAltitudeRequired(false);
    //對周圍的事情是否進(jìn)行關(guān)心
    criteria.setBearingRequired(false);
    //是否支持收費(fèi)的查詢
    criteria.setCostAllowed(true);
    //是否耗電
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    //對速度是否關(guān)注
    criteria.setSpeedRequired(false);
    //得到最好的定位方式
    String provider = locationManager.getBestProvider(criteria, true);
    //注冊監(jiān)聽
    locationManager.requestLocationUpdates(provider, 60000, 0, getListener());
  }
  //取消監(jiān)聽
  public void unRegisterLocationChangeListener(){
    locationManager.removeUpdates(getListener());
  }
  private MyLocationListener listener;
  //得到定位的監(jiān)聽器
  private MyLocationListener getListener(){
    if(listener == null){
      listener = new MyLocationListener();
    }
    return listener;
  }
  //得到上個地理位置
  public String getLastLocation(){
    return sp.getString("last_location", "");
  }
  private final class MyLocationListener implements LocationListener{
    //位置的改變
    public void onLocationChanged(Location location) {
      // TODO Auto-generated method stub
      double latitude = location.getLatitude();//維度
      double longitude = location.getLongitude();//經(jīng)度
      String last_location = "jingdu: " + longitude + ",weidu:" + latitude;
      Editor editor = sp.edit();
      editor.putString("last_location", last_location);
      editor.commit();
    }
    //gps衛(wèi)星有一個沒有找到
    public void onStatusChanged(String provider, int status, Bundle extras) {
      // TODO Auto-generated method stub
    }
    //某個設(shè)置被打開
    public void onProviderEnabled(String provider) {
      // TODO Auto-generated method stub
    }
    //某個設(shè)置被關(guān)閉
    public void onProviderDisabled(String provider) {
      // TODO Auto-generated method stub
    }
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論