Android Location - JamesDansie/data-structures-and-algorithms GitHub Wiki

Android Location

Author: James Dansie

  1. Add stuff to manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.gms.location.sample.basiclocationsample" >

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
  1. Add the client to the instance variable and onCreate
private FusedLocationProviderClient fusedLocationClient;

// ..

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

    fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
}
  1. Add a listener for the last location
fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>(){
... call back stuff
  1. Pass the lat and long to the [2] stuff to get the street address. In particular, will need Geocoder geocoder = new Geocoder(this, Locale.getDefault()); this - this of main activity and Locale gets the user's area for relevant results.

References

  1. https://developer.android.com/training/location/retrieve-current
  2. https://developer.android.com/training/location/display-address
  3. https://developers.google.com/maps/documentation/javascript/geolocation
⚠️ **GitHub.com Fallback** ⚠️