0

Hi I'm new in stackoverflow. I hope someone Know how to do something in Android to call method requestLocationUpdates using FusedLocationApi.

I'm trying to call in a non-activity class that implements the classes nedded to request location updates: LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);

But it shows message that "Cannot resolve method requestLocationUpdates(...)"

 /**
 * Requests location updates from the FusedLocationApi.
 */
protected void startLocationUpdates() {
  LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}

And the non-activity class that I use implements ConnectionCallbacks, OnConnectionFailedListener and LocationListener and extends my activity class.

public class OnMapGps extends OnActivity implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener,
    LocationListener {

    ...
    ...
}

The error that shows is:

Error:(306, 42) error: no suitable method found for requestLocationUpdates(GoogleApiClient,LocationRequest,OnMapGps)
method FusedLocationProviderApi.requestLocationUpdates(GoogleApiClient,LocationRequest,LocationListener)
is not applecable (argument mismatch; OnMapGps cannot be converted to LocationListener) 
Franks
  • 81
  • 1
  • 4
  • It seems you're about to have more problems, given that you say you're extending your Activity class in a "non-activity" class. – Daniel Nugent Mar 14 '16 at 14:55

3 Answers3

5

I found the solution, it seems that i had the wrong import LocationListener. I had

import android.location.LocationListener;

And the correct is

import com.google.android.gms.location.LocationListener;

I think that I had to ask to find the solution myself. :P

Franks
  • 81
  • 1
  • 4
1

I resolved this error by casting 'this' into a 'LocationListener' Object

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, (LocationListener) this);
Amgad
  • 169
  • 2
  • 7
0

[Solution]

import below

import com.google.android.gms.location.LocationListener;

Add the below permission to the manifest file, This is required. After that issues will be resolved.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Code

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);
Thilina Chamika
  • 206
  • 3
  • 4