[英]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) {
}
});
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.