-1

i am trying to getting current location using fused location API.

private void setInitialLocation() {


        if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }

        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, new LocationListener(){
            @Override
            public void onLocationChanged(Location location) {


                mLastLocation = location;

                try {

                } catch (Exception ex) {

                    ex.printStackTrace();
                    Log.e("MapException", ex.getMessage());

                }

            }
        });
    }

android studio giving this error

Class 'Annonymous class derived from LocationListener' must either be declared abstract or implement abstract method.

while i am implementing all the abstract method of Location Listener.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

FusedLocationApi is deprecated. Use this FusedLocationProviderClient

The detailed link is here

Create an instance of FusedLocationProviderClient

mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);


mFusedLocationClient.getLastLocation()
    .addOnSuccessListener(this, new OnSuccessListener<Location>() {
        @Override
        public void onSuccess(Location location) {
            // Got last known location. In some rare situations, this can be null.
            if (location != null) {
                // Logic to handle location object
            }
        }
    });
Archana
  • 597
  • 4
  • 18