【问题标题】:how to retrieve location which is saved using geofire on real time database firebase如何在实时数据库firebase上检索使用geofire保存的位置
【发布时间】:2017-07-07 18:18:23
【问题描述】:

我已经使用 geofire 在实时数据库中保存了我的位置坐标,即在每 3 秒后更新一次的 firebase 现在我想检索我的地图活动中的坐标,即(纬度和经度),但我不知道如何检索它 。我是安卓工作室的新手 here is database pic how the location is saved

我在火力基地中存储位置的方法

     public void onLocationChanged(Location location) {
            FirebaseUser user = fb.getCurrentUser();
            GeoFire geoFire = new 
     GeoFire(databaseReference.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


【解决方案1】:

在你的地图准备好:

 geoFire.getLocation("location", new LocationCallback() {
    @Override
    public void onLocationResult(String key, GeoLocation location) {
        if (location != null) {
            //set marker to display on map
        } else {
            //When location is null
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
       //LogDatabase error
    }
});

【讨论】:

  • 除非不与数据库引用一起使用,否则它将如何检索位置
  • mMap.addMarker(new MarkerOptions().position().title(""));位置写什么?
  • mMap.addMarker(new MarkerOptions().position().title(""));在评论下方 // 设置标记以显示在地图上
  • 但我必须在 position() 中写一些东西??
  • 不使用 LatLan 如何在标记中的位置()中传递一些东西
猜你喜欢
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 2021-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多