androidgeolocationlocationproximitygeofencing

Alert when two users/friends are near to each other - Android Proximity


I tried searching but i couldn't find anything. My Question is "How can i alert 2 or more users if they are nearby each other?" in android using Geo-fencing or something else.

Say, If a UserA is in football ground and UserB walking nearby that football ground. Then UserA and UserB automatically gets notification that UserA/UserB are somewhere nearby.


Solution

  • Finally after spending a couple of hours thinking, I thought a better way to do this:

    1. Setup a database (MySQL,SQL etc) in your server which have users table and location table which have the locations data

    2. In Android create a Service which will fire once in 15 minutes requesting current location.

    3. Create SharedPreference / SQliteDB which holds the last Coordinates of the device which was also updated to the Server database.

      3.1 If the current location matches the Last Location retrieved from the SharedPreference and/or current location within x proximity (depends on how much you give x 30ft or more)
      then user is in the same place so don't upload the coordinates to the Server Database.

      3.2. If the user isn't within proximity or last location doesn't match current location
      then upload the coordinates to the Server Database.

    4. After uploading coordinates to the server, update SharedPreference too...

    5. After uploaded coordinates, The Server must return the User details from its database who are within your proximity. Your app then knows who are near you and send notification to you saying "Your buddy XXX is nearby!"

    6. In Server, after uploading your coordinates, the server will also send notification to the user who are nearby you using Google Cloud Messaging.

    Tips: Run a cron job in your server which will execute every minute and checks "Who is near to Who" and send notification to them.

    Hope it helps somebody :)