如何解决GeoFire半径问题?

时间:2020-06-18 09:20:57

标签: android firebase android-studio geofire

我一直试图通过标记like this 在用户地图上显示附近的合作伙伴,而我的数据库结构为this。如果我在geoFire查询中使用半径5000,它会显示标记,否则它在屏幕上不会显示任何标记。我该如何解决....就像我只想显示3公里左右的标记。 谢谢。

private void getClosestPartners() {

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("partnersAvailable");
    GeoFire geoFire = new GeoFire(ref);
    // creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
    GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(26.796700,80.876134), 3);
    geoQuery.removeAllListeners();
    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            LatLng user = new LatLng(location.latitude, location.longitude);
            String code = user.toString();
            Toast.makeText(getApplicationContext(), code, Toast.LENGTH_LONG).show();
                mMap.addMarker(new MarkerOptions().position(user).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker)));


        }

        @Override
        public void onKeyExited(String key) {
            System.out.println(String.format("Key %s is no longer in the search area", key));
        }

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

        @Override
        public void onGeoQueryReady() {
            System.out.println("All initial data has been loaded and events have been fired!");

        }

        @Override
        public void onGeoQueryError(DatabaseError error) {
            System.err.println("There was an error with this query: " + error);
        }
    });


}

0 个答案:

没有答案