Reading_Notes

View the Project on GitHub Hiba-Almade/Reading_Notes

Location

Using the Google Play services location APIs, your app can request the last known location of the user’s device.

Set up Google Play services

Specify app permissions

To protect user privacy, apps that use location services must request location permissions.

Types of location access

Create location services client

In your activity’s onCreate() method, create an instance of the Fused Location Provider Client as the following code snippet shows.

private FusedLocationProviderClient fusedLocationClient;

// ..

@Override
protected void onCreate(Bundle savedInstanceState) {
    // ...

    fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
}

Get the last known location

Choose the best location estimate

The FusedLocationProviderClient provides many ways to get the device location data,as the following:

  1. getLastLocation() :it get the location quickly and minimize the battery usage ,but the location might be out of date if we don’t use this information fast.

  2. getCurrentLocation() :it get updated and give accurate location but it still do computation on the device. this way is the best to get a fresh location ,and safer than using requestLocationUpdates().

Resources used in this reading

  1. Get the last location