0

Sorry for not providing any sample code because I don't have any idea about how to do this.

I'm coding an Android application which uses Firebase as the backend. I'm storing the current current user location to mysl db using the fusedlocationapi.

Now, when a user is logged into the application, he/she is given a option to show only the list of user around a radius of 25km (let's assume as an example). Can any one guide me with this feature please.

I don.t wanna do this on client side ...is there any way to so it using mysql

Ashith VL
  • 89
  • 3
  • 14
  • What do you want? Show users around with radius of 25km? – RoShan Shan Feb 19 '17 at 08:10
  • Yes Mr.Roshan..could you help with that.,,please – Ashith VL Feb 19 '17 at 08:28
  • Possible duplicate of [How to efficiently find the closest locations nearby a given location](http://stackoverflow.com/questions/3922404/how-to-efficiently-find-the-closest-locations-nearby-a-given-location) – halfer Feb 19 '17 at 10:09
  • Your solution is not relavent to mine..@halfer..I'm having the users lat long in firebase db and i want to list all the users within 25km radius in recycler view..Firstly ur proposed solution is in php and mainly it's not even a close solution to my problem – Ashith VL Feb 19 '17 at 12:13

1 Answers1

0

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.

pastillas
  • 81
  • 6