【问题标题】:I have inserted location using geofire in firebase我在 firebase 中使用 geofire 插入了位置
【发布时间】:2017-07-12 14:33:00
【问题描述】:

我已经在 android studio 中的一项活动中使用 geofire 在 firebase 中插入了位置,现在我想用标记检索单个谷歌地图活动中的所有位置。 我已经创建了地图活动,但我不知道如何从 firebase 检索位置。

请帮助我陷入困境。附带一些源代码。

这是我将位置发送到 firebase 的代码

GeoFire geoFire = new 
GeoFire(databaseReference.child("Location").child(user.getUid()));
          geoFire.setLocation("location", new 
GeoLocation(location.getLatitude(), location.getLongitude()), new 
GeoFire.CompletionListener() {
              @Override
              public void onComplete(String key, DatabaseError error) {
                  if (error != null) {
                      Toast.makeText(gpdfuel.this, "There was an error 
saving the location to GeoFire: " + error, Toast.LENGTH_LONG).show();
                  } else {
                      Toast.makeText(gpdfuel.this, "Location saved on server 
successfully!", Toast.LENGTH_LONG).show();

                  }
              }
          });

【问题讨论】:

    标签: android firebase firebase-realtime-database geofire


    【解决方案1】:

    你必须先创建一个数据引用

     DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/path/");
    

    比地火对象

            GeoFire geoFire = new GeoFire(ref);
    

    现在像这样检索特定范围内的地理定位

     GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, long), radius);
        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
                Log.d(Const.TAG,String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude));
            }
    
            @Override
            public void onKeyExited(String key) {
                Log.d(Const.TAG,String.format("Key %s is no longer in the search area", key));
            }
    
            @Override
            public void onKeyMoved(String key, GeoLocation location) {
                Log.d(Const.TAG,String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
            }
    
            @Override
            public void onGeoQueryReady() {
                Log.d(Const.TAG,"All initial data has been loaded and events have been fired!");
            }
    
            @Override
            public void onGeoQueryError(DatabaseError error) {
                Log.d(Const.TAG,"There was an error with this query: " + error);
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-11
      • 2019-01-05
      • 2018-11-29
      • 2021-10-31
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多