0

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.

Hilal
  • 902
  • 2
  • 22
  • 47

1 Answers1

1

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)

Dus
  • 4,052
  • 5
  • 30
  • 49
  • Yes that makes sense. But onLocationChanged does not called. So I used this also, `mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);` Without using this line, latitude and longitude returns 0. By using it, latitude and longitude are the last location's values and I am waiting new results in onLocationChanged method. What is needed to called onLocationChanged method? How much should I change my location? – Hilal Apr 06 '16 at 09:34
  • I saw the mistake yes it is shame. I cant assign the `LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this)` command to Location object. Thanks! – Hilal Apr 06 '16 at 10:33