Counting users in a geo location - android

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...

Related

Is this the right procedure for sharing location between 2 users?

1) Get user's A and User's B location using Location Services API.
2) Upload User's A and user's B location to a database everytime their location changes.
3) On a specified time-interval - retrieve user's A and user's B to user's B and user's A phones respectively (So that each user has the other user's location).
4) Display the location(longitude, latitude, etc) of the users on the screen.
Or, there is a more efficient way? instead of using time intervals, maybe on-change get location from the database? Or not using database at all? I am finding it hard to even start with a strategy to do that, please point me somewhere to get started
It depends on what do you want in database. If this is only need I would use Firebase as you can use it as realtime database, so any change will come to both users.
If this "location share" needs to be temporary you can create node in firebase db for it, for example userId -> location -> userLat, userLng. Push location updates to the user's location node. Subscribe to another user's node and listen for changes. After the location share is done you can delete the node to clear unneeded data.
More about firebase: https://firebase.google.com/docs/database/

Using Node js to build realtime android app

I want to develop two apps which are related to each other. One is a postman app and another is for users who want to use postman's task.
I have been using node js server which uses socketio. I want to show couple of postmans in user app which they are in location constraint (define specific treshould). When the user taps his map and changes his position, postmans location should updated in user's map and show to them.
In order to design these apps, I had two scenarios in mind.
The first scenario I had, when user changes his position send his location to server and server should get postman's location which is in my defined treshold, but I think it's not optimal because when postmans move realtime in map, server should store their location and updated them and then fetch those to show in user app.
Second one is server broadcast to all postman's app and in postman's app side check treshould and if it's true send back his location to server.
Which of them would be appropriate to develop this situation?

How to send and receive user's location to database and use it in map [Android]

I'm developing a tracking system between two users using android where both have their own android device, this application should work as follow:
the first user's android device has to discover its current location (latitude and longitude).
the user's location (latitude and longitude) has to be uploaded into a database periodically and continuously once the user's location is changed.
the second user's android device retrieves these latitudes and longitude and then displays the first user's location on a googleMap based on them.
I can discover the user's current latitude and longitude for once easily and the database is prepared to receive them and everything is fine, but how to discover them once they changed and keep uploading them into the database continuously ??
In addition to above comments as they perfectly gets user location and for sending location to database use firebase realtime database (you can try it for free) and like a chatting app send users location periodically and receive the same in others mobile by getting the Json from realtime database.
Moreover if you want to limit it between 2 users assign the user same topic"". For more information please deep dive into firebase.
There is an overriden method called onLocationChanged in LocationListener which provides us latest Location whenever user place gets changed.
Reference: LocationListener guidelines
Hope this will help.
Put the same code of fetching current location in onLocation changed. That will automatically update the values every time when change is there in position.

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.
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.

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