Fra*_*nks 0 android location updates locationlistener fusedlocationproviderapi
大家好,我是 stackoverflow 的新手。我希望有人知道如何在 Android 中使用 FusedLocationApi 调用 requestLocationUpdates 方法。
我正在尝试调用一个非活动类,该类实现了请求位置更新所需的类: LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
但它显示消息“无法解析方法 requestLocationUpdates(...)”
/**
* Requests location updates from the FusedLocationApi.
*/
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
Run Code Online (Sandbox Code Playgroud)
我使用的非活动类实现了 ConnectionCallbacks、OnConnectionFailedListener 和 LocationListener 并扩展了我的活动类。
public class OnMapGps extends OnActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
...
...
}
Run Code Online (Sandbox Code Playgroud)
显示的错误是:
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)
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案,看来我导入了错误的LocationListener。我有
import android.location.LocationListener;
Run Code Online (Sandbox Code Playgroud)
正确的是
import com.google.android.gms.location.LocationListener;
Run Code Online (Sandbox Code Playgroud)
我想我必须自己去寻求解决方案。:P