想在此代码中添加completionListner,但不知道如何添加以及在何处添加

时间:2018-10-06 09:33:32

标签: android firebase firebase-realtime-database

private void requestPickupHere(String uid) {
        DatabaseReference dbRequest = FirebaseDatabase.getInstance().getReference("PickupRequest");
        GeoFire mGeoFire = new GeoFire(dbRequest);
        mGeoFire.setLocation(uid,new GeoLocation(mLastLocation.getLatitude(),mLastLocation.getLongitude()));


        if (mUserMarker.isVisible())
            mUserMarker.remove();
        //Add new marker
        mUserMarker = mMap.addMarker(new MarkerOptions()
                .title("Pickup Here")
                .snippet("")
                .position(new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude()))
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

        mUserMarker.showInfoWindow();

        btnPickupRequest.setText("Getting your Driver ....");
    }

想在此处添加完成列表,但我不知道在下面添加这些代码行的位置

尝试添加

之类的CompletionListener
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {@override
public void onComplete(String key, DatabaseError error) {        }

不知道在哪里添加这些行,请帮忙

1 个答案:

答案 0 :(得分:0)

将其添加为setLocation调用的参数。 就您而言:

GeoFire mGeoFire = new GeoFire(dbRequest);
mGeoFire.setLocation(uid, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), new GeoFire.CompletionListener() {
    @Override
    public void onComplete(String key, DatabaseError error) {
        // your code here
    }
});

完整代码:

private void requestPickupHere(String uid) {
    DatabaseReference dbRequest = FirebaseDatabase.getInstance().getReference("PickupRequest");
    GeoFire mGeoFire = new GeoFire(dbRequest);
    mGeoFire.setLocation(uid, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), new GeoFire.CompletionListener() {
        @Override
        public void onComplete(String key, DatabaseError error) {
            // your code here, this is listener
        }
    });


    if (mUserMarker.isVisible())
        mUserMarker.remove();
    //Add new marker
    mUserMarker = mMap.addMarker(new MarkerOptions()
        .title("Pickup Here")
        .snippet("")
        .position(new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude()))
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

    mUserMarker.showInfoWindow();

    btnPickupRequest.setText("Getting your Driver ....");
}