com.google.android.gms.location.FusedLocationProviderClient.getLastLocation()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中com.google.android.gms.location.FusedLocationProviderClient.getLastLocation()方法的一些代码示例,展示了FusedLocationProviderClient.getLastLocation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FusedLocationProviderClient.getLastLocation()方法的具体详情如下:
包路径:com.google.android.gms.location.FusedLocationProviderClient
类名称:FusedLocationProviderClient
方法名:getLastLocation

FusedLocationProviderClient.getLastLocation介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

@SuppressLint("MissingPermission")
private void findLocation() {
 FusedLocationProviderClient client=
  LocationServices.getFusedLocationProviderClient(this);
 client.getLastLocation()
  .addOnCompleteListener(this, this::useResult)
  .addOnFailureListener(this, this::copeWithFailure);
}

代码示例来源:origin: googlemaps/android-samples

Task<Location> locationResult = mFusedLocationProviderClient.getLastLocation();
locationResult.addOnCompleteListener(this, new OnCompleteListener<Location>() {
  @Override

代码示例来源:origin: mohak1712/UberUX

@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
private void onLocationPermissionGranted() {
  if (!checkPermission()) return;
  mMap.getUiSettings().setMyLocationButtonEnabled(false);
  mMap.setMyLocationEnabled(true);
  mFusedLocationClient.getLastLocation()
      .addOnSuccessListener(this, new OnSuccessListener<Location>() {
        @Override
        public void onSuccess(Location location) {
          if (location != null) {
            userLocation = location;
            CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))
                .zoom(17)
                .build();
            addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()));
            mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
          } else {
            userLocation = null;
          }
        }
      });
}

代码示例来源:origin: ruuvi/com.ruuvi.station

private void updateLocation() {
  if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
      @Override
      public void onSuccess(Location location) {
        tagLocation = location;
      }
    });
  }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void getLastLocation() {
 FusedLocationProviderClient fusedLocationClient;
 fusedLocationClient =
  LocationServices.getFusedLocationProviderClient(this);
 if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
   == PERMISSION_GRANTED ||
   ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
   == PERMISSION_GRANTED) {
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     updateTextView(location);
    }
   });
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void getLastLocation() {
 FusedLocationProviderClient fusedLocationClient;
 fusedLocationClient =
  LocationServices.getFusedLocationProviderClient(this);
 if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
   == PERMISSION_GRANTED ||
   ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
   == PERMISSION_GRANTED) {
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     updateTextView(location);
    }
   });
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void getLastLocation() {
 FusedLocationProviderClient fusedLocationClient;
 fusedLocationClient =
  LocationServices.getFusedLocationProviderClient(this);
 if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
   == PERMISSION_GRANTED ||
   ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
   == PERMISSION_GRANTED) {
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     updateTextView(location);
    }
   });
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void getLastLocation() {
 FusedLocationProviderClient fusedLocationClient;
 fusedLocationClient =
  LocationServices.getFusedLocationProviderClient(this);
 if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
   == PERMISSION_GRANTED ||
   ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
   == PERMISSION_GRANTED) {
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     updateTextView(location);
    }
   });
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void getLastLocation() {
 FusedLocationProviderClient fusedLocationClient;
 fusedLocationClient =
  LocationServices.getFusedLocationProviderClient(this);
 if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
   == PERMISSION_GRANTED ||
   ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
   == PERMISSION_GRANTED) {
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     updateTextView(location);
    }
   });
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

private void listing15_5() {
 int permission = ActivityCompat.checkSelfPermission(this,
  ACCESS_FINE_LOCATION);
 if (permission == PERMISSION_GRANTED) {
  // LISTING 15-5: Obtaining the last known device Location
  FusedLocationProviderClient fusedLocationClient;
  fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
  fusedLocationClient.getLastLocation()
   .addOnSuccessListener(this, new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location) {
     // In some rare situations this can be null.
     if (location != null) {
      // TODO Do something with the returned location.
     }
    }
   });
 }
}

代码示例来源:origin: mitchtabian/Google-Maps-Google-Places

private void getDeviceLocation(){
  Log.d(TAG, "getDeviceLocation: getting the devices current location");
  mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
  try{
    if(mLocationPermissionsGranted){
      final Task location = mFusedLocationProviderClient.getLastLocation();
      location.addOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(@NonNull Task task) {
          if(task.isSuccessful()){
            Log.d(TAG, "onComplete: found location!");
            Location currentLocation = (Location) task.getResult();
            moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
                DEFAULT_ZOOM,
                "My Location");
          }else{
            Log.d(TAG, "onComplete: current location is null");
            Toast.makeText(MapActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
          }
        }
      });
    }
  }catch (SecurityException e){
    Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage() );
  }
}

代码示例来源:origin: neXenio/BLE-Indoor-Positioning

@SuppressLint("MissingPermission")
public static void requestLastKnownLocation() {
  final AndroidLocationProvider instance = getInstance();
  if (!instance.hasLocationPermission()) {
    return;
  }
  Log.d(TAG, "Requesting last known location");
  instance.fusedLocationClient.getLastLocation()
      .addOnSuccessListener(getInstance().activity, new OnSuccessListener<android.location.Location>() {
        @Override
        public void onSuccess(android.location.Location androidLocation) {
          if (androidLocation != null) {
            instance.onLocationUpdateReceived(androidLocation);
          } else {
            Log.w(TAG, "Unable to get last known location");
          }
        }
      });
}

代码示例来源:origin: ruuvi/com.ruuvi.station

private void updateLocation() {
  FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getApplicationContext());
  if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
      @Override
      public void onSuccess(Location location) {
        tagLocation = location;
      }
    });
  }
}

代码示例来源:origin: aliumujib/Nibo

@Override
  public void subscribe(final ObservableEmitter<Location> source) throws Exception {
    FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(context);
    locationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
      @Override
      public void onSuccess(Location location) {
        if (location != null) {
          source.onNext(location);
        }
      }
    }).addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
        source.onError(e);
      }
    });
  }
}).subscribeOn(Schedulers.io())

代码示例来源:origin: ruuvi/com.ruuvi.station

mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
  @Override
  public void onSuccess(Location location) {

代码示例来源:origin: owntracks/android

@SuppressWarnings("unused")
@Subscribe(sticky = true)
public void onEvent(Events.PermissionGranted event) {
  Timber.v("location permission granted");
  removeGeofences();
  setupGeofences();
  try {
    Timber.v("Getting last location");
    mFusedLocationClient.getLastLocation().addOnCompleteListener(this);
  } catch (SecurityException ignored) {
  }
}

代码示例来源:origin: ruuvi/com.ruuvi.station

mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
  @Override
  public void onSuccess(Location location) {

代码示例来源:origin: TeamWalrus/Walrus

fusedLocationProviderClient.getLastLocation().addOnSuccessListener(
    new OnSuccessListener<Location>() {
      @Override

相关文章