如何使用geofire和JSON

时间:2018-03-20 13:52:55

标签: java android geofire

我使用geofire构建应用程序,但是当我从JSON文件中放入多个侦听器时,我尝试删除任何侦听器,它会向我显示此错误:

  

java.lang.IllegalArgumentException:尝试删除已删除或未添加的侦听器!

我尝试从geoQuery.queryAtLocation为每个听众重复onResponse

在我的代码下面,当我使用JSON

加载多个侦听器时
public void getMarkers(View view) {

        StringRequest strReq = new StringRequest(Request.Method.POST, "myweb.com/markers.php", new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.e("Response: ", response);

                try {
                    JSONObject jObj = new JSONObject(response);
                    String getObject = jObj.getString("saagMRK");
                    JSONArray jsonArray = new JSONArray(getObject);


                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);

                        // Menambah data marker untuk di tampilkan ke google map

                        t1 = valueOf(jsonObject.getString("r_lat"));
                        t2 = valueOf(jsonObject.getString("r_lng"));

                        geoQuery = geofire.queryAtLocation(new GeoLocation(parseDouble(jsonObject.getString(LAT)),parseDouble(jsonObject.getString(LNG))), 0.1f);
                        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {

                                                              @Override
                                                              public void onKeyEntered(String key, GeoLocation location) {
                                                                  sendNotification("elGEos", String.format("ooohh" + " ha sido notificado", key));


                                                                  geoQuery.removeGeoQueryEventListener(this);


                                                              }

                                                              @Override
                                                              public void onKeyExited(String key) {
                                                                  sendNotification("elGEos", String.format("%s has salido del area peligrosa", key));
                                                                  // geofire.removeLocation(key);


                                                              }

                                                              @Override
                                                              public void onKeyMoved(String key, GeoLocation location) {
                                                                  Log.d("MOVE", String.format("%s mover entre el area peligrosa [%f/%f]", key, location.latitude, location.longitude));
                                                              }

                                                              @Override
                                                              public void onGeoQueryReady() {


                                                              }

                                                              @Override
                                                              public void onGeoQueryError(DatabaseError error) {
                                                                  Log.e("ERROR", "" + error);
                                                              }
                                                          }
                        );//here

                        addMarker(latLng, title, snnipet, latLng2);






                    }

                } catch (JSONException e) {
                    // JSON error
                    e.printStackTrace();

                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Error: ", error.getMessage());
                Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();

            }
        });


        AppController.getInstance().addToRequestQueue(strReq, tag_json_obj);
    }

0 个答案:

没有答案