Error with Google Places Api (.addConnectionCallbacks)


public class Places_DATA extends ActionBarActivity
{
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_places);

    mGoogleApiClient = new GoogleApiClient
            .Builder(this)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}

问题是我在.addConnectionCallbacks(this(中一直收到一个错误。错误表明.ConnectionCallbacks不能添加到类中。我不确定我做错了什么,因为我一直在关注谷歌的文档,如下所示:https://developers.google.com/places/android/start

除非是ConnectionCallbacksOnConnectionFailedListener,否则不能使用this。您可以通过让您的活动实现这些接口来实现这一点。

public class Places_DATA extends ActionBarActivity
    implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_places);
        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }
    @Override
    public void onConnected(Bundle connectionHint) {
        // We are now connected!
    }
    @Override
    public void onConnectionSuspended(int cause) {
        // We are not connected anymore!
    }
    @Override
    public onConnectionFailed(ConnectionResult result) {
        // We tried to connect but failed!
    }
}

相关内容

  • 没有找到相关文章

最新更新