gpt4 book ai didi

java - 使用 GeoFire 和 Firebase 将用户位置添加到实时 map

转载 作者:行者123 更新时间:2023-11-30 01:16:49 25 4
gpt4 key购买 nike

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

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

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

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

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

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

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

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

最佳答案

设置位置

 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为了完全理解。

关于java - 使用 GeoFire 和 Firebase 将用户位置添加到实时 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37732617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com