【问题标题】:GooglePlayServicesClient and ConnectionCallbacksGooglePlayServicesClient 和 ConnectionCallbacks
【发布时间】:2014-03-11 12:09:03
【问题描述】:

我初始化 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

【问题讨论】:

  • 您好,您解决了吗?我目前面临同样的问题;)

标签: android google-play-services locationlistener


【解决方案1】:

使用 isGooglePlayServicesAvailable,它检查服务的可用性。

【讨论】:

  • 我在连接之前使用
【解决方案2】:

您是否在任何地方实例化 GoogleApiClient?喜欢:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

【讨论】:

    猜你喜欢
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多