I'm trying to request location updates via the location client in the onConnected method. My fragment implements LocationListener, GooglePlayServicesClient.ConnectionCallbacks, and GooglePlayServicesClient.OnConnectionFailedListener.

Code looks like this.

public class AnimatedMapFragment extends SupportMapFragment 
                implements LocationListener,
                           GooglePlayServicesClient.ConnectionCallbacks,
                           GooglePlayServicesClient.OnConnectionFailedListener {

    private LocationRequest mLocationRequest;
    private LocationClient mLocationClient;

    ...

    mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(5000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    mLocationClient = new LocationClient(this.getActivity(), this, this);

    ...

    @Override
    public void onConnected(Bundle bundle) {
        mLocationClient.requestLocationUpdates(mLocationRequest, this);
    }

And the error is "no suitable method found for requestLocationUpdates(LocationRequest, AnimatedMapFragment)" Which is highly confusing because in the docs for location client, there is this definition of requestLocationUpdates.

public void requestLocationUpdates (LocationRequest request, LocationListener listener)

Does anyone see what I'm missing?

有帮助吗?

解决方案

In case others run into this problem, just figured it out. Make sure you are importing:

com.google.android.gms.location.LocationClient;

I was importing android.location.LocationClient.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top