SHARE
TWEET

Untitled

a guest May 25th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private FusedLocationProviderClient fusedLocationProviderClient;
  2.    private LocationRequest locationRequest;  
  3.    private LocationCallback locationCallback;
  4.  
  5.    fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
  6.    
  7.    fusedLocationProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
  8.             @Override
  9.             public void onSuccess(Location location) {
  10.                 if (location != null) {
  11.                  //do something
  12.                 }
  13.             }
  14.         });
  15.        
  16.     locationRequest = new LocationRequest();
  17.     locationRequest.setInterval(2000);
  18.     locationRequest.setFastestInterval(2000);
  19.     locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
  20.     locationCallback = new LocationCallback() {
  21.             @Override
  22.             public void onLocationResult(LocationResult locationResult) {
  23.                 super.onLocationResult(locationResult);
  24.                 for (Location location : locationResult.getLocations()) {
  25.                     if (location != null) {
  26.                        //do something
  27.                     }
  28.                 }
  29.             }
  30.         };
  31.    
  32.     fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, getMainLooper());
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top