简体   繁体   English

我想计算用户半径并在Android Firebase中检索用户ID

[英]I want to calculate user radius and retrieve the user id in android Firebase

I want that when user uploads posts so the notification should be sent to the user in 10 km radius. 我希望当用户上传帖子时将通知发送到半径10 km的用户。 For this, I am calculating user radius by retrieving user latitude and longitude from firebase database and sending them to the distanceBetween function one by one along with the latitude and longitude of the post from where it is uploaded. 为此,我要通过从Firebase数据库中检索用户的纬度和经度,并将它们连同上传位置的帖子的纬度和经度一一发送到distanceBetween函数,来计算用户半径。 But the problem is that which user comes in the radius.And I am unable to retrieve the user id and reg Token to send a notification. 但是问题是哪个用户进入了半径范围,而且我无法检索用户ID和reg令牌来发送通知。

Here is my code 这是我的代码

dataref.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
                    @Override
                    public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {

                        for (com.google.firebase.database.DataSnapshot data : dataSnapshot.getChildren()) 
                            {
                             datasnap = data;
                                            }

Location.distanceBetween(Post_latitude, Post_longitude,Double.parseDouble(datasnap.child("latitude").getValue(String.class)), Double.parseDouble(datasnap.child("longitude").getValue(String.class)), results);
                        final double km = (results[0] / 1000);

                        if (km <= 10000) {
                            if (!String.valueOf(datasnap.getKey().toString()).equals(userID)) {

                //getting the user id here

                               Log.d("USerID", datasnap.getKey().toString() )
                            }
                        }

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

Here is my database image 这是我的数据库图像

I have found the solution of my problem. 我找到了解决我问题的方法。 Use geofire to save and retrieve user location with in a specified radius. 使用geofire以指定半径保存和检索用户位置。

here is the code: 这是代码:

// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6); //在[37.7832,-122.4056]周围创建一个半径为0.6公里的新查询。GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832,-122.4056),0.6);

For details check the link: https://github.com/firebase/geofire-java 有关详细信息,请检查链接: https : //github.com/firebase/geofire-java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想从 firebase 检索当前用户的 ID 并将其写入另一个节点,但它一直拒绝 - I want to retrieve a current user's ID from firebase and write it in another node, but it just keeps denying 想要从 android 中的 Firebase 检索单个用户信息 - want to retrieve single user information from Firebase in android 我想从Firebase用户数组中检索所有用户的UID并将其存储到Arraylist中 - I want to retrieve all user's UID from Firebase user array and store it into Arraylist 在android中获取firebase用户id - Get firebase user id in android 如何从 Firebase Android 中的用户 ID 获取用户 object - How can I get User object from its user id in Firebase Android 我想创建唯一的用户ID - I want to create unique user id 我想从数据库中检索保存的电影数据,并将其显示给用户android - I want to retrieve the saved movies data from database and show it to user android 如何使用 Firebase 在 Android Studio 项目中将记录的用户数据作为用户名检索到导航标头 - How can I retrieve Logged user data to nav header as Username in Android studio project with Firebase 如何使用 Android 在 Firebase 实时数据库中检索经过身份验证的用户的用户数据 - How to retrieve user data of authenticated users in Firebase Realtime Database with Android Android:如何从Firebase中的当前用户检索数据? - Android: How to retrieve data from a current user in firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM