【问题标题】:Fused location - locationclient not connected inside onConnected method融合位置 - 在 onConnected 方法中未连接 locationclient
【发布时间】:2014-05-06 16:24:16
【问题描述】:

我正在尝试使用 Fused Location API 在我的应用中获取位置。

我所做的是调用 LocationClient.connect(),然后在 onConnected 方法中查找位置。

我没想到的是:

IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

但我在 onConnected 方法中! O_o

即使我在那里,我显然也完全没有连接到服务!那我该怎么办?

这是引发错误的代码:

        Geocoder geoCoder = new Geocoder(this.getActivity(), Locale.getDefault());

        String locationCity = "";

        try {
            Location loc = locationclient.getLastLocation();
        ...

【问题讨论】:

    标签: android google-maps google-play-services android-location location-client


    【解决方案1】:

    在 onCreate() 方法中调用 locationClient.connect()。

    并在 onConnected() 方法中添加如下检查

    if (locationclient != null && locationclient.isConnected()) {

    locationclient.requestLocationUpdates(locationrequest, this);

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多