Gostaria de sabe, como implementar outro método que funcione , pois esse método esta depreciado
package alura.curso.br.com.agenda;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
public class Localizador implements GoogleApiClient.ConnectionCallbacks, LocationListener {
private final GoogleApiClient client;
private final GoogleMap mapa;
private Context context;
public Localizador(Context context, GoogleMap mapa){
client = new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.build();
client.connect();
context.this = context;
this.mapa = mapa;
}
@Override
public void onConnected(@Nullable Bundle bundle) {
LocationRequest request = new LocationRequest();
//gps so vai atualizar se mover acima de 50 metros
request.setSmallestDisplacement(50);
//sao condicoes Se(If) e so vai atualizar quando passar 1 segundo(por isso 1000 esta em milisegundos)
request.setInterval(1000);
//priorizando melhor localizacao
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if(ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},753);
}
if(ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},73);
}
LocationServices.FusedLocationApi.removeLocationUpdates(client,request,this);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
LatLng coordenada = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(coordenada);
mapa.moveCamera(cameraUpdate);
}
}
Se não implementa desse jeito mais, se podia explicar como funciona na implementação do novo código.