ERRORS can not resolve symbol REQUEST_LOCATION

0

I'm getting the following errors: Error 1: can not resolve symbol REQUEST_LOCATION, Error 2: FusedLocationApi, appears crossed out.

when I try to request permission

This is the code fragment

    public void onConnected(Bundle bundle) {
        Log.d(TAG, "onConnected");

        locationRequest = LocationRequest.create();
        locationRequest.setInterval(1000); // milliseconds
        locationRequest.setFastestInterval(1000); // the fastest rate in milliseconds at which your app can handle location updates
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);


// this line of error



        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {
            // Check Permissions Now
            ActivityCompat.requestPermissions(this,
                    new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
                    REQUEST_LOCATION);
        } else {
            // permission has been granted, continue as usual
            Location myLocation =
                    LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        }

        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);

    }
    
asked by Andres Arango 30.12.2017 в 17:38
source

1 answer

0

I'll explain what is happening to you:

1) ActivityCompat.requestPermission receives 3 parameters the first is the activity that you are sending it well, the second is an Array with the permissions you want to obtain that you are also doing well, the third parameter is the requestCode that is not more that a number that you send and with which you can ask for the answer in the method onRequestPermissionsResult .

To eliminate the error, you just have to create a global variable like this:

public static final int REQUEST_LOCATION = 1; //Pueses colocar cualquier numero

2) With respect to which you leave crossed out FusedLocationApi that means that this method is deprecated that is unadvised for use.

Here is a link where they talk about this topic: FusedLocationApi

    
answered by 30.12.2017 в 18:47