尽管无休止地调用 onGeoQueryReady,但永远不会触发 Geofire onKeyEntered

Posted

技术标签:

【中文标题】尽管无休止地调用 onGeoQueryReady,但永远不会触发 Geofire onKeyEntered【英文标题】:Geofire onKeyEntered is never triggered though onGeoQueryReady is called endlessly 【发布时间】: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 如果你愿意,我可以给你看调试屏幕的截图 【参考方案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 会在每个孩子的正下方寻找 .priorityg

【讨论】:

van 我已经正确实现了 geofire , OnGeoQueryReady 调用并完成了他的工作,但 onKeyEntered 和 onKeyExited 从未调用过。你可以在这里看到我的问题github.com/firebase/geofire-java/issues/… 如果您有新问题,请发布新问题,而不是评论之前的答案。请务必将minimal, complete/standalone code with which anyone can reproduce the problem 包含在您的新问题中。

以上是关于尽管无休止地调用 onGeoQueryReady,但永远不会触发 Geofire onKeyEntered的主要内容,如果未能解决你的问题,请参考以下文章