【问题标题】:Geoquery to find out the app user within the radius of 1 km of current location of the user not working地理查询以找出用户当前位置1公里半径内的应用程序用户不工作
【发布时间】:2017-12-31 04:28:40
【问题描述】:

我想检索用户当前位置 1 公里半径内存在的所有 android 应用用户的列表。下面是我正在尝试的代码,作为回报,它给了我自己的 latlong。帮助我找出我错在哪里。

 double radius = 100;

 databaseReference = FirebaseDatabase.getInstance().getReference();
GeoFire geoFire = new GeoFire(databaseMediCare);
mAuth = FirebaseAuth.getInstance();
String uid = mAuth.getCurrentUser().getUid();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("userLocation");
final List<String> data = new ArrayList<>();
databaseReference .child("users").child(mAuth.getCurrentUser().getUid()).child("geocordinates").child("latitude").setValue(latitude);
databaseReference .child("users").child(mAuth.getCurrentUser().getUid()).child("geocordinates").child("longitude").setValue(longitude);
databaseReference .child("users").child(mAuth.getCurrentUser().getUid()).child("availability").setValue(true);
geoFire.setLocation(uid, new GeoLocation(latitude, latitude));
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), radius);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
    @Override
    public void onKeyEntered(String key, GeoLocation location) {
        //showToast("geocodes successfully found");
        data.add(key);
        Location itemLocation = new Location("itemLocation");
        itemLocation.setLatitude(location.latitude);
        itemLocation.setLongitude(location.longitude);
       // Log.d("distance to " + key" is", userLocation.distanceTo(itemLocation) + "");
        Log.i("geocodes Number of users", String.valueOf(data.size()));
    }

        @Override
        public void onKeyExited(String key) {
            Log.i(key, "geocodes left the place");
            data.remove(key);
        }

        @Override
        public void onKeyMoved(String key, GeoLocation location) {
            Log.i(key, "geocodes key moved but here");
        }

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

        @Override
        public void onGeoQueryError(DatabaseError error) {
            Log.i("geocodes", "error occured");
        }

    });

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-authentication geofire


    【解决方案1】:

    您可以使用 PlaceLikehood 代替 Geoquery。 You can see at this link.

    PlaceLikehood 为您提供附近的地点。然后,通过 Location.distanceTo 方法获取距离。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2020-05-03
      相关资源
      最近更新 更多