-
Notifications
You must be signed in to change notification settings - Fork 0
Android Location
James Dansie edited this page Nov 13, 2019
·
2 revisions
- 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>
- Add the client to the instance variable and onCreate
private FusedLocationProviderClient fusedLocationClient;
// ..
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
}- Add a listener for the last location
fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>(){
... call back stuff- 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.