Google Location Services API:
Author(Danny) - http://goo.gl/d55bpz
Package “android.location”
-
LocationManager.GPS_PROVIDER: Determines location using
satellites. Depending on the conditions, this provider may take a while
to return a location fix.
-
LocationManager.NETWORK_PROVIDER: Determines location based on
availability of nearby cell towers and WiFi access points. This is
faster than GPS_PROVIDER.
Google Location Services API
-
Simplicity: Unlike the previous API, you no longer have to deal
with multiple providers. Instead, you specify high-level needs, such as
“high accuracy” or “low power”, and it will take a suitable approach.
-
Availability: Gives your app immediate access to the best, most
recent known location. Usually this information is readily available,
you just have to ask for it.
-
Power-efficiency: Minimizes your application’s usage of power.
-
Versatility: Meets a wide range of needs, from foreground uses -
needing highly accurate location data, to background uses - requiring
only periodic location updates with negligible power impact.
Requesting Permission, Configuring AndroidManifest.xml
Androids have specific security features that would prevent any arbitrary application from requesting a precise user location. To solve this, we need to edit “AndroidManifest.xml” and add the permission we require for this application:
While we are at it, we should also define the version of Google Play Services we are using for this application:<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />Checking for Google Play Services Availability:
Before accessing features provided by Google Play Services, we must check if the device has Google Play Services installed, and that the version is the one we intend to use (6.5.87).
This method will check for Google Play Services, and in case the device doesn’t have it installed (it’s rare, but I’ve seen such cases), it will open a dialog with the corresponding error and invite the user to install/update Google Play Services from the Google Play Store.private boolean checkGooglePlayServices(){ int checkGooglePlayServices = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mContext); if (checkGooglePlayServices != ConnectionResult.SUCCESS) { /* * Google Play Services is missing or update is required * return code could be * SUCCESS, * SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, * SERVICE_DISABLED, SERVICE_INVALID. */ GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, mContext, REQUEST_CODE_RECOVER_PLAY_SERVICES).show(); return false; } return true; }
Accessing Google APIs
To access Google APIs, we just need to perform one more step: create an instance of GoogleApiClient. The Google API Client provides a common entry point to all the Google Play services, and manages the network connection between the user’s device and each Google service.
Github Source: https://github.com/dtrejogo/google-location-services-api

