Я добавил местоположение с помощью geofire в firebase

так местоположение сохраняется в firebase

Я вставил местоположение с помощью geofire в firebase из одного из действий в студии Android, теперь я хочу получить все местоположение в одном действии карты Google с маркером. Я создал действие карты, но не знаю, как получить местоположение из базы данных.

Пожалуйста, помогите, я застрял в этом. С некоторым исходным кодом.

Вот мой код для отправки местоположения в firebase

GeoFire geoFire = new 
GeoFire(databaseReference.child("Location").child(user.getUid()));
          geoFire.setLocation("location", new 
GeoLocation(location.getLatitude(), location.getLongitude()), new 
GeoFire.CompletionListener() {
              @Override
              public void onComplete(String key, DatabaseError error) {
                  if (error != null) {
                      Toast.makeText(gpdfuel.this, "There was an error 
saving the location to GeoFire: " + error, Toast.LENGTH_LONG).show();
                  } else {
                      Toast.makeText(gpdfuel.this, "Location saved on server 
successfully!", Toast.LENGTH_LONG).show();

                  }
              }
          });

person Parth Tiwari    schedule 12.07.2017    source источник


Ответы (1)


сначала вам нужно создать ссылку на данные

 DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/path/");

чем объект geofire

        GeoFire geoFire = new GeoFire(ref);

теперь получить геолокацию в определенном диапазоне, как это

 GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, long), radius);
    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            Log.d(Const.TAG,String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude));
        }

        @Override
        public void onKeyExited(String key) {
            Log.d(Const.TAG,String.format("Key %s is no longer in the search area", key));
        }

        @Override
        public void onKeyMoved(String key, GeoLocation location) {
            Log.d(Const.TAG,String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
        }

        @Override
        public void onGeoQueryReady() {
            Log.d(Const.TAG,"All initial data has been loaded and events have been fired!");
        }

        @Override
        public void onGeoQueryError(DatabaseError error) {
            Log.d(Const.TAG,"There was an error with this query: " + error);
        }
    });
person saurabh dixit    schedule 13.09.2017