Skip to content

Instantly share code, notes, and snippets.

@saddahussain
Created May 15, 2019 11:13
Show Gist options
  • Save saddahussain/0df0c5594ef3c8dccb43f0d207504040 to your computer and use it in GitHub Desktop.
Save saddahussain/0df0c5594ef3c8dccb43f0d207504040 to your computer and use it in GitHub Desktop.
private FusedLocationProviderClient fusedLocationProviderClient;
private LocationRequest locationRequest;
private LocationCallback locationCallback;
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
fusedLocationProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
//do something
}
}
});
locationRequest = new LocationRequest();
locationRequest.setInterval(2000);
locationRequest.setFastestInterval(2000);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
for (Location location : locationResult.getLocations()) {
if (location != null) {
//do something
}
}
}
};
fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, getMainLooper());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment