Search code examples
javaandroidmobilelocationgetlocation

Cant get the location and address of the user


[So i have that problem that it gives me an error like:

error: incompatible types: <anonymous LocationCallback> cannot be converted to PendingIntent
                LocationServices.getFusedLocationProviderClient(getActivity()).requestLocationUpdates(locationRequest, new LocationCallback() {

So how can i get over it ? I want to find the address of the user and update it. I have also fragments that i have to write "this" instead of getActivity() but it gives an error each way.]1


Solution

  • In the photo attached the error is shown because you have not rewritten the code completely you are missing the 3rd parameter looper

    your code should be something like

    LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, new LocationCallback() {
                        @Override
                        public void onLocationResult(LocationResult locationResult) {
                            //All your code for parsing or extracting data
                        }
                    },
                    Looper.myLooper());