Хотите добавить завершение в этот код, но не знаете, как и куда добавить - PullRequest
0 голосов
/ 06 октября 2018
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 голосов
/ 06 октября 2018

Добавьте его в качестве параметра для вызова 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 ....");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...