【问题标题】:GeoFire data has invalid format exceptionGeoFire 数据有无效的格式异常
【发布时间】:2016-10-29 16:52:35
【问题描述】:

我正在为我的 Android 应用设置 GeoFire。在从 Firebase 数据库检索数据开始时,我收到以下异常。

获取 GeoFire 位置时出错:DatabaseError:从 Firebase 数据库运行循环调用的用户代码引发了异常: W/System.err:java.lang.Throwable:GeoFire 数据的格式无效:{lon=74.529964, lat=31.4479225}

显然,它正在从数据库中检索数据,但仍然抛出异常:(

我已使用以下代码检索数据:

geoFire.getLocation("test1", new LocationCallback() {
        @Override
        public void onLocationResult(String key, GeoLocation location) {
            if (location != null) {
                System.out.println(String.format("The location for key %s is [%f,%f]", key, location.latitude, location.longitude));
            } else {
                System.out.println(String.format("There is no location for key %s in GeoFire", key));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            System.err.println("There was an error getting the GeoFire location: " + databaseError);
        }
    });

由于我是 firebase 新手,有什么明显的我遗漏的吗?This is how my firebase database looks like

【问题讨论】:

  • 该错误消息听起来像是 GeoFire 认为数据库中的数据无效。请在您的问题中添加数据库是如何填充的。
  • @MichaelKarcher 我附上了数据库结构的屏幕截图。我已尝试检索 test1 和 test2 的数据。他们都给出了同样的错误

标签: android firebase firebase-realtime-database geofire


【解决方案1】:

GeoFire 似乎没有像您在示例中那样使用键 latlon,或 LatitudeLongitude,而是在名为“g”的属性中对位置进行了一些自定义编码。保存位置供 GeoFire 使用的正确方法似乎是 GeoFire 提供的 setLocation 方法。

请参阅How to save GeoFire coordinates along with other items in Firebase database?,了解您的数据库中的结构应该是什么样子的讨论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    相关资源
    最近更新 更多