【问题标题】:Adding user locations to live map using GeoFire and Firebase使用 GeoFire 和 Firebase 将用户位置添加到实时地图
【发布时间】:2016-06-09 17:29:13
【问题描述】:

我开发了一个 Android 应用程序,其用户登录和注册链接到 Firebase 数据库,我还添加了一个列表视图来存储添加到 textView 中的信息。

我已经研究过使用 GeoFire,因为我希望当前登录的用户显示在地图上。

我查看了 Firebase 提供的一个示例,但我仍然不确定该怎么做,关于这个主题的教程并不多。

这是链接到公共数据库的代码行

    private static final String GEO_FIRE_REF = "https://https://publicdata-transit.firebaseio.com/_geofire.firebaseio.com/_geofire";

我的地图显示了此示例上的帐户位置。

我的问题是,有人知道如何将我的用户位置添加到地图中吗?我是这项技术的新手,我不太了解它。

如果您需要更多代码或信息,请告诉我。

【问题讨论】:

    标签: java android google-maps firebase geofire


    【解决方案1】:

    设置位置

     geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973));
    

    要检查写入是否成功保存在服务器上,您可以将 GeoFire.CompletionListener 添加到 setLocation 调用:

    geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973), new GeoFire.CompletionListener() {
        @Override
        public void onComplete(String key, FirebaseError error) {
            if (error != null) {
                System.err.println("There was an error saving the location to GeoFire: " + error);
            } else {
                System.out.println("Location saved on server successfully!");
            }
        }
    });
    

    请查看Official documentation 以获得完整的理解。

    【讨论】:

    • 我将位置设置为旧金山,这是示例位置,我也不确定将这段代码放在哪里?你认为那段代码会在地图上添加我的用户位置吗?我正在提供打车服务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    相关资源
    最近更新 更多