Sending Geo Locations periodically to server - android

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

Related

Can I fetch the data being given to an app by its host and store it locally?

I would like to preface my query by saying that I am an absolute beginner when it comes to programming but I really want to realise this project so every little help is deeply appreciated.
I am trying to build an app that needs accurate train data for it to work and from my current research as there is not central government API for railway data , the only accurate data source for train location that I can find is in an other app that uses crowd sourcing to pinpoint the location.
I wanted to know if it is possible to fetch that train data from that app and then use it on my own as it would make my app a lot more reliable and accurate.
The issue currently is that the app only shows graphical representation of the data thats being fed to it from its servers , so I wanted to know if there is a way to access the actual data being sent to the app.
Thank you.
Let me clarify, this is a very broad question and hence will have a very broad answer too.
As far as I can understand from your question is that you want to show TRUE location on a map.
For this, you will have to understand the complete Tracking scenario. Let me explain it to you step-wise below:
There is an app, installed on a device (user) which fetches the GPS location (REAL) data and keeps sending it to a server (backend).
This GPS data is the Lattitude-Longitude coordinates of the device (user).
The server stores this information in their database for queries.
There is another user, different than the one currently sending the location data, who wants to know the location of the first user. The app which he is using will request the server (backend) to send the location data for the device. Which, in turn, will send the latest location data (LatLng coordinates) to the current app. This app will then show the location data over a map.
Now, usually, this process is followed to show one-to-one location data. However, in scenarios like Train Location etc, servers usually collect pool of location data, being received from several users, to cross-verify the actual location (average out, mean, location optimization algorithms etc.) and then display that information over a map.
As per your requirement, which I can understand, you want to get this REAL data directly from either another app or from the server. If you want to get the location data from the server, you will need an API, which serves as a Request-Response platform. However, if you are looking to get the data from another app, it would rather be simpler to get the location data directly, as your APP will also be installed on the device itself.
I would suggest you to kindly read about getting and processing location data, communication with servers over API etc for better understanding and implementation of your requirements.

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.

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.

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