【问题标题】:FusedLocationApi MapView in Fragment - addConnectionCallbacks, onConnectionSuspendedFusedLocationApi MapView in Fragment - addConnectionCallbacks, onConnectionSuspended
【发布时间】:2015-02-01 04:36:16
【问题描述】:

我在一个片段中有一个MapView,我遇到了两个我似乎无法找到解决方案的问题。我已经搜索过,但我没有看到其他人有这些问题。作为参考,我主要关注开发者页面上的this 教程。

这是我的片段:

public class MapFragment extends Fragment
        implements GooglePlayServicesClient.ConnectionCallbacks,
                   GooglePlayServicesClient.OnConnectionFailedListener,
                   LocationListener

第一个问题在这里:

 mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)  //problem!
            .addOnConnectionFailedListener(this) //problem!
            .build();

调用addConnectionCallbacks(this) 会出现错误,指出它不能应用于myPackageName.MapFragment。我知道你必须在这里传递一个GoogleApiClient.ConnectionCallbacks 监听器,但我看到的每个示例都使用this,我不知道该怎么做。 addOnConnectionFailedListener 也出现了同样的问题。在我的片段中,我实现了所有必要的方法,例如onLocationChanged()

第二个问题在这里:

@Override
public void onConnectionSuspended(int i)
{
    Log.i(TAG_MAP_FRAGMENT, "GoogleApiClient connection has been suspended");
}

这会给出一条错误消息:Method does not override method from its superclass。我已经搜索过,但找不到其他有此问题的人。我不确定如何处理它。

有人知道如何解决这些问题吗?感谢您的帮助!

【问题讨论】:

    标签: android google-api-client fusedlocationproviderapi


    【解决方案1】:

    代替:

    implements GooglePlayServicesClient.ConnectionCallbacks,
               GooglePlayServicesClient.OnConnectionFailedListener
    

    尝试:

    implements GoogleApiClient.ConnectionCallbacks,
               GoogleApiClient.OnConnectionFailedListener
    

    这解决了上面最初发布的所有三个问题。 然而,现在方法onDisconnected() 被标记为错误method does not override method from superclass

    当你使用所有四个时错误已修复:

    implements GooglePlayServicesClient.ConnectionCallbacks,
               GooglePlayServicesClient.OnConnectionFailedListener,
               GoogleApiClient.ConnectionCallbacks,
               GoogleApiClient.OnConnectionFailedListener
    

    这似乎并不理想,但至少目前有效。如果您偶然发现此问题并且知道更好的解决方法,请留下回复。

    【讨论】:

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