Find people near me - GPS location

Hello,

I know that we could check user current position, but is it possible to find people which are within 100km from my current position?

If you store the longitude, latitude of users in your database you then you could use some math to calculate the distance between them. Here is a javascript function that takes 2 sets of longitude/latitude as input and outputs the distance between them in meters:

function measure(lat1, lon1, lat2, lon2){  // generally used geo measurement function
    var R = 6378.137; // Radius of earth in KM
    var dLat = lat2 * Math.PI / 180 - lat1 * Math.PI / 180;
    var dLon = lon2 * Math.PI / 180 - lon1 * Math.PI / 180;
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
    Math.sin(dLon/2) * Math.sin(dLon/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var d = R * c;
    return d * 1000; // meters
}

You might could do this in a Flow Function

1 Like

@JOHN_WORSHAM, thank you for this!

I think that its wont be helpful as I need to show list of items based on provided criteria. Let’s say that it will work like Tinder.

If user specify that want to see only people which are whitin 100km from him I need to show him only those users, so it cannot be dynamic search record by record.

I found that Google Firebase offer something like Geohash for Geo Queries: Geo queries  |  Firebase Documentation

I think that this solution is more what I am looking for.

What do you think?