- LocationCallback (interface)
- GeofenceCallback (interface)
Obviously, they can be separated into two groups. The first group consists of LocationCallback & GoogleLocationApiManager and the second group consists of GeofenceCallback & GeofencingManager.
Lets have a closer look at each of the two groups and their responsibilities!
The first group (LocationCallback & GoogleLocationApiManager) is responsible for providing the location awareness feature to our application. The GoogleLocationApiManager handles this process.
Location manager VS Google Services
I won’t go deep into the discussion of which approach is better, but I will give my two cents on the topic. Obviously, the Android Location API was present back in Android API level 1. That was long looong ago! And step by step, some more features were included in that particular package. At some point in time, the folks from Google, decided to improve even further the location-based functionality for Android. So they came up with a separated location service included in their not infamous Google Services package.
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. In most cases, you’ll get better battery performance, as well as more appropriate accuracy, by using the Location Services API.
If you want to have a closer look on the topic, check this article!
Also it provides a basic notification mechanism in order to inform the presenter layer for any particular changes related to the user’s location. Remember that the MapsPresenterImpl class acts like a hub in our app?
Here you will find a brief description of the some of the methods in the GoogleLocationApiManager class:
- onConnected() – this method is invoked when a connection between our application and Google Services was established. If you take a closer look at the constructor, you will see that this is the place where we launch our connection process. Two two most important things that this method does is that it extracts the user’s last know location from the servic and registers the current class as the one responsible for handling location updates, pending results and so on.
pendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,mLocationSettingsRequestBuilder.build());mLastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
- onConnectionSuspended() – the method is invoked whenever your app is temporarily in a disconnected state, due to problems with the remote service. The GoogleApiClient will automatically try to reconnect to Google Play services, but during the time, the connection is down, you should disable all UI components which rely on the service.
- onConnectionFailed() – this method is called if there was a problem when connecting your application with the Google Play services. The difference between this method and the one mentioned above is that, the onConnectionSuspended() is called if there was a problem with the connection AFTER it was established.
- onLocationChanged() – this is pretty much self explanatory. Whenever the user’s location is changed, this method will be invoked, so that we will be able to handle the new location in the appropriate way – save it, update the map UI, etc.
Feel free to share, comment & give your opinion on the topic!
And only if you really REALLY liked the article, you can buy me a cup of coffee! Otherwise, don’t do it! Donate $1