You can use Google Maps Android API utility library
public class DistanceHelper {
private static final Double RADIUS = 25000.0;
public static double getDistance(LatLng user1, LatLng user2){
double distance = SphericalUtil.computeDistanceBetween(user1, user2);
return distance;
}
public static Double getRadius(){
return RADIUS;
}
public static String formatNumber(double distance) {
String unit = "m";
if (distance < 1) {
distance *= 1000;
unit = "mm";
} else if (distance > 1000) {
distance /= 1000;
unit = "km";
}
return String.format("%4.3f%s", distance, unit);
}
}
LatLng user1 = new LatLng(currentUser.getLatitude(), currentUser.getLongitude());
LatLng user2 = new LatLng(otherUser.getLatitude(), otherUser.getLongitude());
Double distance = DistanceHelper.getDistance(user1, user2);
if (distance <= DistanceHelper.getRadius()) {
//code here
}
I store the users' latitude and longitude in FB database using GPS and LocationManager. put the calculation inside your ChildEventListener to retrieve get users inside 25km radius.
However I think this implementation is wrong because the calculations are done on client side so what if you have million or billion of users then you have to compute each one by one on client's device which might cause very slow performance of your app.