I have inserted location using geofire in firebase

前端 未结 1 712
我在风中等你
我在风中等你 2021-01-28 07:24

I have inserted location using geofire in firebase from one of the activity in android studio now I want to retrieve all the location in single google map activity wi

1条回答
  •  执笔经年
    2021-01-28 08:05

    you have to create a data reference first

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

    than geofire object

            GeoFire geoFire = new GeoFire(ref);
    

    now retreive geo firelocation within particular range like this

     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);
            }
        });
    

    0 讨论(0)
提交回复
热议问题