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

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/

Related

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.

Store user data and allow users to add data from a public list

Im making an app wich allows users to get weatherdata from several sources at specific locations.
The problem i am facing is that pr. now when a user uses my app he/she will see all the location objects in the firebase database. (Im planning to add login via firebase , login will be needed for this feature)
How can i easily store the users choosen locations in the app ?
For example :
I would like to have a List of Locations Y, Z, X and so on. (Each with their own set of data,updated by the users)
User A wants to see Location Y and Z, User B wants to see Location Y and X
How should i store a link to the locations that user A wants to see ? and then be able to show those locations in a RecycleView.
Preferably i would also like that if user C joins he can add his own location or choose from a list of locations.
Since you are already using Firebase Database, store the User's preferenes on that. You can create a separate node for users, and store each user using the UID as the key (not necessary though) and the preferences or any other detail as the value. Something like this
"root":{
"users":{
"UID1":{
"locations":{
"location1":true
"location2":true
}
}
"UID2":{
"locations":{
"location2":true
"location3":true
}
}
"UID3":{
"locations":{
"location4":true
"location5":true
}
}
}
}
Then you can get a reference to each user using
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference userRef = FirebaseDatabase.getInstance()
.getReference("users/" + user.getUid() + "/locations");
You can pass this reference to a FirebaseRecyclerAdapter to get a populate a RecyclerView. However, if the data stored in each list item is small, say just a name and maybe a picture_url, then just store under each user. This may duplicate data but gets the data quickly, which is what a realtime database is supposed to do.
The only way I see it is by implementing a login functionality. In this way you will know which is the current user.
Then, when you have that functionality, you have two options:
Use SharedPreferences. You must mach the selected locations with the current user and that info will be saved locally on the device. Each time a user logged in, you must check if there are any previously saved data for the current user. NOTE: THIS IS A LAME APPROACH!!!
Implement some kind of a back-end for the app to communicate with. In this way all the info for the locations will be stored on a remote machine and user A will be able to log in from different devices and will see the same info. By using the first approach that won't be possible!

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

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