如何限制GeoFire for Android返回的密钥范围?

时间:2016-07-21 17:24:55

标签: android firebase firebase-realtime-database geofire

我端对端地跟踪了this文档,并且还在StackOverflow上询问了与此问题相关的6-7多个问题。我还写了一封邮件给Firebase支持。

我在GeoFire中保存了一些数据以及FirebaseDatabase坐标。它会像这样得到保存:

enter image description here

现在,我正在尝试使用此代码检索它:

geoQuery = geoFire.queryAtLocation(new GeoLocation(currentLatDouble, currentLngDouble), 0.5);

        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {

    databaseReference.child("requests").addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            Map<String, String> newRequest = (Map<String, String>) dataSnapshot.getValue();
                            imageUID = newRequest.get("imageUIDh");
                            hDescription = newRequest.get("hDescription");
                            currentLat = newRequest.get("currentLat");
                            currentLng = newRequest.get("currentLng");
                            postedBy = newRequest.get("postedBy");
                            postedAtTime = newRequest.get("postedAtTime");
                            postedOnDate = newRequest.get("postedOnDate");
                            utcFormatDateTime = newRequest.get("utcFormatDateTime");

                            String timeStr = utcFormatDateTime;
                            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            df.setTimeZone(TimeZone.getTimeZone("UTC"));
                            Date date = null;
                            try {
                                // error on the line below
                                date = df.parse(timeStr);
                                //
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            df.setTimeZone(TimeZone.getDefault());
                            final String persisted = df.format(date);

                            // Parse string from DB - UTC timezone
                            Date parsed = null;
                            try {
                                parsed = df.parse(persisted);
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            // Now convert to whatever timezone for display purposes
                            final SimpleDateFormat displayFormat = new SimpleDateFormat("h:mm a");
                            displayFormat.setTimeZone(TimeZone.getDefault());

                            formattedTime = displayFormat.format(parsed);

                            prepareDataForRequests();
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                            Snackbar snackbar = Snackbar
                                    .make(coordinatorLayout, databaseError.getMessage(), Snackbar.LENGTH_LONG);
                            snackbar.setDuration(Snackbar.LENGTH_SHORT);
                            snackbar.show();
                            progressBarLoadingRequests.setVisibility(View.INVISIBLE);
                        }
                    });
}

            @Override
            public void onKeyExited(String key) {

            }

            @Override
            public void onKeyMoved(String key, GeoLocation location) {

            }

            @Override
            public void onGeoQueryReady() {
                Toast.makeText(getBaseContext(), "geoQueries retrieved", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onGeoQueryError(DatabaseError error) {
                Toast.makeText(getBaseContext(), "Error retriving geoquery", Toast.LENGTH_SHORT).show();
            }
        });

问题是从我身边1000公里发布的帖子也被检索到了从我0.1公里处张贴的帖子也被检索到了,但是只发布了0.5公里内的帖子本应该出现。

如何实现这一目标?

0 个答案:

没有答案