im init LocationClient和LocationRequest
locationClient = new LocationClient(context, this, this);
request = LocationRequest.create();
request.setInterval(MIN_TIME);
request.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setFastestInterval(FAST_INTERVAL_CEILING_IN_MILLISECONDS);
连接到GooglePlayServices
locationClient.connect();
并在执行回调方法时请求位置更新
@Override
public void onConnected(final Bundle bundle)
{
locationClient.requestLocationUpdates(request, this);//this exception point
}
但抛出异常
java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
at com.google.android.gms.internal.k.B(Unknown Source)
at com.google.android.gms.internal.bh.a(Unknown Source)
at com.google.android.gms.internal.bh$c.B(Unknown Source)
at com.google.android.gms.internal.bg.requestLocationUpdates(Unknown Source)
at com.google.android.gms.internal.bh.requestLocationUpdates(Unknown Source)
at com.google.android.gms.internal.bh.requestLocationUpdates(Unknown Source)
at com.google.android.gms.location.LocationClient.requestLocationUpdates(Unknown Source)
at ru.etransport.locationlib.LocationListenerGPs.onConnected(LocationListenerGPs.java:45)
更新:我在连接前使用 isGooglePlayServicesAvailable
答案 0 :(得分:0)
使用isGooglePlayServicesAvailable,它会检查服务的可用性。
答案 1 :(得分:0)
您是否在任何地方实例化 GoogleApiClient ?像:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();