Created
May 15, 2019 11:13
-
-
Save saddahussain/0df0c5594ef3c8dccb43f0d207504040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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