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

3

4

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.

Mutter answered 8/10, 2014 at 13:55 Comment(0)
M
5

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 :)

Mutter answered 9/10, 2014 at 14:15 Comment(0)
C
3

It's too simple. Just send your mobile location to the database and use this query while searching for nearby users:

$query = "select * from 
    (SELECT name,latitude,longitude,round((((acos(sin((".$latitude."*pi()/180)) * 
    sin((`latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`latitude`*pi()/180)) * 
    cos(((".$longitude."- `longitude`)*pi()/180))))*180/pi())*60*1.1515*1.609344),1) as distance
FROM location) as temp order by distance";

For more info I have made a post on that.

http://www.freebieslearning.info/android-2/android-find-nearby-user/

I hope this will help you.

Coles answered 9/1, 2017 at 14:31 Comment(0)
A
-2
  1. On A device query your own position trough android location api.
  2. On A device send the result to your friends
  3. On B device receive the Device A location
  4. On B device send the Device B location to Device A.
  5. Calculate the distances between A and B. Display notification if distance requirements were met.

There is a lot o ways of how to do it.

Amoral answered 8/10, 2014 at 14:9 Comment(1)
Not satisfied! 1st) How come the device of UserA continuously updates its own location to the server or to the UserB? It will dry up the juice 2nd) Sending location information of the UserA to UserB and UserC can be done using?Mutter

© 2022 - 2024 — McMap. All rights reserved.