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

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.

Finally after spending a couple of hours thinking, I thought a better way to do this:
Setup a database (MySQL,SQL etc) in your server which have users table and location table which have the locations data
In Android create a Service which will fire once in 15 minutes requesting current location.
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.
After uploading coordinates to the server, update SharedPreference too...
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!"
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 :)

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.

On A device query your own position trough android location api.
On A device send the result to your friends
On B device receive the Device A location
On B device send the Device B location to Device A.
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.

Related

Making a Android chat app and finding people nearby

Hi everyone I'm in trouble one of my friends asked for a chating Android app which it could find "People Nearby" using this app and first I said yes I can make it but now I'm unable to do.
so It's my very first app that I'm making it for someone I wanted to know if "People Nearby" is simple function for an app or it's complicated and hard to make it
I've seen this kind of apps like swarm that shows you people nearby
but unfortunately I can't find any help or source or tutorial for it the only thing I could find was Google's Nearby Messages which I'm not sure that's what I'm looking for
so I would be very happy if you could help me or at least tell me where I can find a help.
Server side:
(You can use python flask for this kind of simple requirement If you do not have experience in server side scripting)
Your API's must have.
/register -> Registering user profile (unique id, name, location etc) and save it in database.
/receive_location -> Receive location (lat lang values), update in the user profile and check with all records in your database who is in the radius(defined by you or get this as from user) and return the list of user details to client.
Client side:
Have an IntentService which will post location of the client to the server at certain intervals returns the list of users who are in the radius you define.
User googleApiClient to get the location and server .
http://developer.android.com/training/location/retrieve-current.html
Use recycler view to show this result. Send a local broadcast from intent service to tell the activity containing recycler view to update it.
Basic requirement for this is you must have server where all user data is stored.
You must have all users updated latitude and longitude.
To get updated latitude and longitude you must call your api at periodic times.
If you want nearby people search you must call api with your current latitude and longitude, then from server and your api must filter all users location and gives you nearby people.

How to retrieve the location of another android device?

First of all I would like to mention that this would be done with the consent of all users!
That being said, what I am trying to create is an application where the users would see their location and the location of all the other connected users (latitude and longitude).
I am pretty sure the best way to do that would be to send data to a server and then have each device retrieve that data but I would like to know if there exist other ways of doing this. Or perhaps someone could point me in the right direction on how to create such a system with a server retrieving and sending data to android devices ?
GPS coordinates will do for you. You can get the coordinates and save in server then all the coordinates of a particular device can be retrieved by any connected device.
We have Location and LocationManager in android which shall do the job for you. Read more about these in the Android Developers

Counting users in a geo location

I would like to implement a user count in a particular location on a map in HTML5. The HTML5 code would be implemented inside an Android application. Here are the steps what i have thought of:
Store the latitudes & longitudes of the location in a server side database.
Store a counter variable at server side database.
Users opens the Android application (current location calculated).
If current location is approx = to stored location then
=> XMLHttpRequest object sent to database server that stores the user's IP address and increments the counter
I have two issues. One is how to identify a user so that it is counted only once. IP address is not a very good way of doing that as it can be different for same user (user using Wifi and 3G). Second is to keep on updating the user list every 3-5 minutes
First I would recommend to use geofences (see http://developer.android.com/training/location/geofencing.html) for the location you want to track. That way you don't really need to handle the location yourself, but your app gets notified when a user enters (or leaves) the given area (location + radius).
To identify the user I'd suggest to create a UUID ( http://developer.android.com/reference/java/util/UUID.html#randomUUID() ), store it locally (e.g. in a SharedPreference ) and send it along with the location update...
I'm not sure about keeping the list up to date, since I'm not really familiar with ajax...

Sending Geo Locations periodically to server

I have a list of registered users . I want to compare their location with the current user . I know I need to send the location coordinates periodically to the server. This would be done within a service . I am not sure at what time I should obtain the location coordinates of the users :- At the registration time or login time.
Please provide me some suggestions what is the right time to save the location details into the server.
I am new to android.
(Pardon me if this is something silly I am asking for).

limit one area and browse other people are using the same app

When my app is triggered, it takes the current position of the user through the GPS (this function already implemented).
My question is: I want to know for example if I have users who are using my app in a given radius (1km for example). Is it possible?
Yes, but you need a server as well. Broadly speaking, the process is as follows:
The app gets the location from Android.
The app queries the server, sending the current location in its request.
The server stores the location and the user name in a spatial database; that is, a database of users that can be indexed by location. It overwrites the previous location if there was one. The server should also store the time the location was set.
The server also looks up the location in the spatial database to find all the users in the given radius, or the nearest n users. It sends the list of users back to the app. It might use JSON, XML, or some other format to send these data. (Since you control both the server and the app, you can choose whatever format you like.)
The app reports its position to the server again if the device's location changes, and gets a new list of users.
You can also use Google Cloud Messaging, or a persistent connection, to let the server notify the app when new users appear nearby, if your application needs that.
When the user goes offline, the app sends another message to the server to tell it. This erases the user's location for the database so this user won't show up after he has left the area.
The server should also delete locations from the database if they haven't been updated in a certain amount of time, in case the app crashed or got disconnected abruptly.
For the server, you can implement something on top of PostGIS, for example. PostGIS is a plugin for PostgreSQL that allows it to answer spatial queries.
This is a very specific need, so I don't think there's any existing code you can download to do this for you. Once you've tried it out, ask a new question if you get stuck.

Categories

Resources