Location

PERMISIONS :

ACCESS_COARSE_LOCATION - Network

 ACCESS_FINE_LOCATION - GPS

ACCESS_BACKGROUND_LOCATION


FusedLocationProviderClient - Main entry point for accessing location for the app and interacts with google play services behind the scenes

GooglePlayServices 11.6.0 and above for 8.0(Oreo) and Above

LocationRequest - contains quality of service parameters for requests to FusedLocationProviderClient 

Location Callback - onLocationAvailability, onLocationResult

onSuccesListener and onFailureListener with onSuccess and onFailure callback

Location - gives lat and long

Dependancy(App) : com.google.android.gms:play-services-location:17.0.0

Classpath :  com.google.gms:google-services


locationProviderClient = LocationServices.getFusedLocationProviderClient(this)

locationRequest =  LocationRequest.create()

locationRequest.setPriority(LocationRequest.Priority_High_Accuracy)

locationRequest.setInterval(5000);

locationCallback = new LocationCallback(){

onLocationAvailability and onLocationResult - to be implemented

}

Location currentLocation;

StartLocationRequest

locationProviderClient.requestLocationUpdates(locationRequest, locationCallback , MainActivity.this.getMainLooper())

locationProviderClient.getLastLocation().addOnSuccessListener {

onSuccess(Location location)

currentLocation = location

}

locationProviderClient.getLastLocation().addOnFailureListener {

}

StopLocationRequest

locationProviderClient.removeLocationUpdates(locationCallback)


MapActviity implements onMapReadyCallback interface

implement onMapReady method

onMapReady() {

mMap = googleMap;

LatLng currentPlace = new Latlng(currentLocation.getLattitude(), currentLocation.getLattitude());

mMap.addMarker(new MarkerOptions().position(currentPlace).title("Home")

mMap.animateCamera(new CameraUpdateFactory.newLatLngZoom(currentPlace, 15.0f))

mMap.moveCamera(CameraUpdateFactory.newLatLng(currentPlace))

Comments

Popular posts from this blog

Stack and Queue

Merge 2 Arrays

Java Concepts