Search code examples
javaandroidfirebasegeolocationgeofire

Create location-based app without saving coordinate


I developed a location-based application that operates in the following way:

  1. I save the location of a user by using Geofire as follows (saves lat,on coordinate in firebase database):

    if (UID != null) {
    geoFire.setLocation( UID, new GeoLocation( Lat_Coordinate, Lon_Coordinate ), (key, error) -> {
        if (error != null) {
    
        } else {
    
        }
    } );
    }
    
  2. I perform Geofire query in order to find users in a specific distance decides by the users:

     geoFire.getLocation( PersonID, new com.firebase.geofire.LocationCallback() {
         @Override
         public void onLocationResult(String key, GeoLocation location) {
             if (location != null) {
                 float distance = CalculateDistance( Lat, Lon, location.latitude, location.longitude );
                 if (!PersonID.equals( UID )) {
                     if (distance <= Radius) {
                         distance = distance / 1000;
                         MapPerson mapPerson = new MapPerson( PersonID, String.valueOf( Math.round( distance ) ), itemID );
                         personList.add( mapPerson );
    
                         Collections.sort( personList, (o1, o2) -> o2.getPersonDistance().compareTo( o1.getPersonDistance() ) );
                         Collections.reverse( personList );
                         mapPersonAdapter.notifyDataSetChanged();
    
                         rv_RecyclerView.setVisibility( View.VISIBLE );
    
                     }
                 }
             }
         }
    

Which basically looks for the location of other people and calculates the distance relative to me.

Now, it all works fine and correctly.

However, I would like to save the least possible information about the users due to privacy limits.

Is there any technique to perform such calculations or recommended algorithm to find users around me in some radius without saving their location into my firebase database?

Thank you


Solution

  • Is there any technique to perform such calculations or recommended algorithm to find users around me in some radius without saving their location into my firebase database?

    No, there is not. Without knowing their actual location, you cannot know if the users are near or not. There is no special technique that can detect if the users are within a specific radius. The only way to achieve this is to store the location in the database and use a library like Geofire, to perform the desired geo queries. A workaround might be, to store the location of the user only when the user is active, otherwise don't.