Ejemplo n.º 1
0
 /**
  * 请求获取位置信息
  *
  * @param onceLocation 是否只定位一次
  * @param aMapLocationListener 定位回调接口,该回调接口中的方法不会立即被调用
  */
 public static void requestLocation(
     boolean onceLocation, AMapLocationListener aMapLocationListener) {
   stopLocation();
   if (sAMapLocationClient == null) {
     sAMapLocationClientOption = new AMapLocationClientOption();
     sAMapLocationClientOption.setLocationMode(
         AMapLocationClientOption.AMapLocationMode.Battery_Saving);
     sAMapLocationClientOption.setInterval(4000);
     sAMapLocationClient = new AMapLocationClient(App.getInstance());
   }
   sAMapLocationClientOption.setOnceLocation(onceLocation);
   sAMapLocationClient.setLocationOption(sAMapLocationClientOption);
   sAMapLocationClient.setLocationListener(aMapLocationListener);
   sAMapLocationClient.startLocation();
 }
Ejemplo n.º 2
0
 public void getLocation() {
   if (MyUtils.selfPermissionGranted(
       Manifest.permission.ACCESS_COARSE_LOCATION, getApplicationContext())) {
     dialog.setCanceledOnTouchOutside(false);
     dialog.setMessage("正在定位,请稍后...");
     dialog.show();
     locationClient = new AMapLocationClient(getApplicationContext());
     locationClient.setLocationListener(this);
     locationOption = new AMapLocationClientOption();
     // 设置定位模式为低功耗模式
     locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
     locationOption.setNeedAddress(true);
     // 设置定位参数
     locationClient.setLocationOption(locationOption);
     // 启动定位
     locationClient.startLocation();
   } else {
     ActivityCompat.requestPermissions(
         instance,
         new String[] {Manifest.permission.ACCESS_COARSE_LOCATION},
         Constant.LOCATION_STATE);
   }
 }