How FusedLocationProviderClient
differ with FusedLocationProviderApi
what sort of things get solved using new FusedLocationProviderClient
please tell major difference at code level and internal working of both.
Asked
Active
Viewed 881 times
1

AskNilesh
- 67,701
- 16
- 123
- 163

Nikhil Singh
- 300
- 2
- 13
1 Answers
3
With the 11.0.0 release of Google Play Services, it is introduced a new way to access to LocationServices. Now, some manually managed functions like connection to Play Services are not required.
The new LocationServices APIs are much simpler and will make your code less error prone. The connection logic is handled automatically, and you only need to attach a single completion listener:
FusedLocationProviderClient client =
LocationServices.getFusedLocationProviderClient(this);
client.requestLocationUpdates(LocationRequest.create(), pendingIntent)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
Log.d("MainActivity", "Result: " + task.getResult());
}
});
The new API immediately improves the code in a few ways:
- The API calls automatically wait for the service connection to be established, which removes the need to wait for onConnected before making requests.
- It uses the Task API which makes it easier to compose asynchronous operations.
- The code is self-contained and could easily be moved into a shared utility class or similar.
- You don't need to understand the underlying connection process to start coding.
For more detail, you can read this blog.

ahmet koçu
- 81
- 3