安卓定位客户端无法解决方法问题

4

我正试图在onConnected方法中通过位置客户端请求位置更新。我的片段实现了LocationListener、GooglePlayServicesClient.ConnectionCallbacks和GooglePlayServicesClient.OnConnectionFailedListener。

代码如下:

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);
    }

错误提示为"no suitable method found for requestLocationUpdates(LocationRequest, AnimatedMapFragment)",这很令人困惑,因为在位置客户端文档中,有这样一个requestLocationUpdates的定义:

public void requestLocationUpdates (LocationRequest request, LocationListener listener)

有没有人看出我错过了什么?

1个回答

7
若有人遇到此问题,请注意导入以下内容: com.google.android.gms.location.LocationClient; 我曾经导入了android.location.LocationClient。

2
谢谢!另外,对于LocationListener,你应该导入com.google.android.gms.location.LocationListener。我为此奋斗了三个小时! - Nirmal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接