Search code examples
androidgpsgoogle-play-serviceslocation-servicesandroid-fusedlocation

FusedLocationApi.requestLocationUpdates gives Incompatible Types Error


I am using Google Play services to get current location. When I am using requestLocationUpdates method it gives red lines saying; Incompatible types. Required: android.location.Location. Found:com.google.android.gms.common.api.PendingResult

mLastLocation = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);

this refers to LocationListener. I already implement com.google.android.gms.location.LocationListener and override onLocationChanged method but still red line exists. To be able to sure I tried this version also;

mLastLocation = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {

                }
            });

This also gives same error. Method parameters are GoogleApiClient, LocationRequest, LocationListener. I don't understand where is the mistake. Any idea ? Thanks in advance.


Solution

  • You don't need to assign mLastLocation. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); Since your class implements LocationListener, you're supposed to receive your location changes on onLocationChanged(Location location). Did you see the formal samples and explanation ? if not, this will be usefull : http://developer.android.com/intl/pt-br/training/location/receive-location-updates.html

    Read more on : http://developer.android.com/intl/pt-br/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)