Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any advantages of using FusedLocationProviderApi over LocationManager?

Earlier to get user current location I have used LocationManager:

LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}

It is easy to read and very straightforward code.

But I have noticed that Google recently released New Client API Model in Google Play Services and suggests to use FusedLocationProviderApi which looks like much more complicated, it is async, it requires to handle callbacks etc.

Are there any advantages of using FusedLocationProviderApi over LocationManager?

like image 539
Vadims Savjolovs Avatar asked May 09 '15 20:05

Vadims Savjolovs


People also ask

What advantages do you get in using Google Play services API over the android framework API for the location feature?

The Google Location Services API, part of Google Play Services, provides a more powerful, high-level framework that automatically handles location providers, user movement, and location accuracy. It also handles location update scheduling based on power consumption parameters you provide.

What is fused location used for?

The fused location provider is a location API in Google Play services that intelligently combines different signals to provide the location information that your app needs.

Is fused location provider free?

No Google doesn't charge you anything for using FusedLocationProvider . It is free of cost.

What is Fusedlocationproviderclient?

Requests location updates with the given request and results delivered to the given callback on the specified Executor . Task<Void> requestLocationUpdates(LocationRequest request, LocationCallback callback, Looper looper)


1 Answers

FusedLocationProvider uses a mix of hardware to determine location based on the context of the request, meaning it's optimized transparently to you. It will also cache captured locations between applications to avoid unnecessary work to determine location info. So if a user has a variety of location-aware apps, they potentially avoid taxing the device (and waiting) for a location capture as one may have already been cached.

While the ol' LocationManager will suffice in small, one-off situations, you should definitely consider the newer alternative as the benefits may be great, and the work to implement, easy.

You may as well use it as Google Play Services is regularly updated across devices, and continuously includes improvements to location-based features (and more).

A link to an explanation of the FusedLocationProvider at launch: https://www.youtube.com/watch?v=Bte_GHuxUGc

like image 199
Paul Cafardo Avatar answered Sep 22 '22 12:09

Paul Cafardo