【问题标题】:Geofire onKeyEntered is never triggered though onGeoQueryReady is called endlessly尽管无休止地调用 onGeoQueryReady,但永远不会触发 Geofire onKeyEntered
【发布时间】:2018-12-02 15:07:00
【问题描述】:

代码如下。我已经看到所有以前提出的问题,他们犯了写错误参考或没有使用 Geofire.set 方法设置 geofire 的错误。请帮助

  private void georadius(final LatLng pickup)
    {
        //geo
        DatabaseReference r2=root.child("Active_Drivers");
        GeoFire mG=new GeoFire(r2);

        GeoQuery m=mG.queryAtLocation(new GeoLocation(pickup.latitude,pickup.longitude),radius);
        m.removeAllListeners();

        m.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
               if (driverfound==false) {
                   driverfound = true;
                   driverid = key;
                   driverlocation = new LatLng(location.latitude, location.longitude);
               }
            }

            @Override
            public void onKeyExited(String key) {

            }

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

            }

            @Override
            public void onGeoQueryReady() {

                if (driverfound==false)
                {
                    radius++;
                    georadius(pickup);

                }

            }

            @Override
            public void onGeoQueryError(DatabaseError error) {

            }
        });
    }

我的 JSON:

{
  "Active_Drivers" : {
    "LgEnzsB4y3g0tQZEnIMJRFnnREU2" : {
      "location" : {
        ".priority" : "ttqwsbkq5d",
        "g" : "ttqwsbkq5d",
        "l" : [ 30.6762423, 76.85536 ]
      }
    }
  },
  "Customer Requests" : {
    "nCz2Rlk2SafeTXWarBs4T8EiIdm2" : {
      "location" : {
        ".priority" : "ttqwsbu1fy",
        "g" : "ttqwsbu1fy",
        "l" : [ 30.6782832, 76.8549792 ]
      }
    }

【问题讨论】:

  • 请编辑您的问题以在Active_Drivers 下包含 JSON 的 sn-p(作为文本,请不要截图)。您可以通过单击Firebase Database console 中的“导出 JSON”链接来获取此信息。
  • @FrankvanPuffelen 我照你说的做了……
  • 如果onKeyEntered 没有重复触发,onGeoQueryReady 似乎不太可能重复触发。如果你在if (driverfound==false) { 上设置断点,它会被命中吗?
  • @FrankvanPuffelen 先生,我已经使用断点进行了调试,导致半径增加到大量数字,即 2076 等,这在 onGeoQueryReady 中发生。但从未触发 onKeyEntered...
  • @FrankvanPuffelen 如果你愿意,我可以给你看调试屏幕的截图

标签: android firebase firebase-realtime-database geofire


【解决方案1】:

您的数据结构看起来与this 示例不同:

{
  "fish1" : {
    "g" : "pns0h0mf2u",
    "l" : [ -53.435719, 140.808716 ]
  },
  "fish2" : {
    "g" : "u417k3dwub",
    "l" : [ 56.83069, 1.94822 ]
  },
  "fish3" : {
    "g" : "8m3rz3s480",
    "l" : [ 30.902225, -166.66809 ]
  }
}

每个孩子都有一个额外的location 级别。我很确定 Geofire 会在每个孩子的正下方寻找 .priority 和 g。

【讨论】:

猜你喜欢
  • 2019-03-25
  • 2019-05-19
  • 1970-01-01
  • 1970-01-01
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 2019-09-16
  • 2014-05-15
相关资源
最近更新 更多