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

北城余情 提交于 2019-12-07 16:30:51

问题


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.


回答1:


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




回答2:


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.




回答3:


  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.



来源:https://stackoverflow.com/questions/26258697/alert-when-two-users-friends-are-near-to-each-other-android-proximity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!