1

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

这是我的片段:

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. 我已经搜索过,但找不到其他有此问题的人。我不确定如何处理它。

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

4

1 回答 1

4

代替:

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

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

于 2015-02-05T07:46:33.427 回答