Android showing users on Map - java

On iOS I created an application where a user can share his location and other users could see him on the MapView.
I did this by getting the location with a location manager, whenever it changed by x meters, and then wrote the lat/long with a device id to a database using a PHP script. The other user could then press a button to show the locations on a map by retrieving this data from the database.
Now here is my question. First I think this is the way to make a application like this. If you think there is a more efficient way please let me know.
What is the best method to update this data for showing users on the map?
For my iOS app I used a timer which would get the lat/long from the database every 30s or so, but I dont believe this is the most efficient or best method. The app would have to load the data every second even if another user has not changed his position.
Could you also push me in the right direction on how to animate the pin from the old location to the new location?
Thanks in advance.

Because there are no answers I used old method which is using a timer to update the latt / long in my database. Works ok btw but was wondering if there is a better way.

Related

So am building an app and it has this feature that i dont know exactly how to go about it

I hope this makes a bit sense, basically, I have this feature in my app for tracking calories which consists of having this page that only appears the first time you use the feature and it asks you to add personal details (so it can make the right calculations), after that you get faced with a simple page that tracks your nutrition with a button for the user to insert the meals he has eaten, this page has to save the inserted data (via firebase) and then restart from 0 each and every day.
my first problem is I don't know how I make the page that only appears one time to save personal data(to be more precise I don't know how to make only appears the first time). and the second problem is how do I make the app automatically sends the given data at the end of each day?
interface in normal state, interface when adding the meals
hopefully, this 2 images will help you get a better grasp of what am trying to explain
don't worry am not looking for someone to straight up solve it all for me, I just need some orientation about what type of things/functions I need to do to solve these 2 problems
While #Narendra_Nath's answer might work, please note that is not a bulletproof solution. Why? Because a SharedPreferences doesn't persist across app uninstalls. This means that your user can install and uninstall the app and see the page as much as they want. So if you indeed want a user to see a screen only once, then you should consider storing that data in a database. Please note that SQLite isn't also a solution because when a user uninstalls the app, everything that is stored locally is wiped out. So what's the solution?
The best way to solve this would be to store the data in the cloud, either in Cloud Firestore or in the Realtime Database. So you can set a boolean variable and always check against it.
If you however intend to implement Firebase Authentication, then another solution would be to display the screen when your users are authenticated for the first time. So even if they will try to sign in on another device, install and uninstall the app, they won't be able to see the screen again.
Regarding the second problem, you should consider using Cloud Function for Firebase. It's the most elegant solution. If you want to somehow schedule an operation, then you should consider using Cloud Scheduler, as explained in my answer in the following post:
Is it not possible to have a code in the background who will be called every 24h?
Make the page that only appears one-time -> store a value in the shared preferences "isInfoShownToUser -> false" then do a check when the app starts to check if this value is false or true. If it is false show the "take the info" page .. then turn the value to false in the shared preferences.
How do I make the app automatically send data -> Use a Workmanager implementation to send data to the server (Firebase) at a particular time ..
Or use a implementation like the first one which uploads the data to the server just once everyday

Android java how to get location as variable

I want to create an app where the user enters a name for his/her current location and then it will save the latitude, longitude and altitude in a simple sharedPreferences file...
Things I need :
I don't want is to use internet, because it will be used in an area where there is no cell signal.
I know it will probably take longer to load coordinates without internet.. So I want to ask if it is possible to use a progress bar to indicate when it is done??...
Thanks a lot to anyone who helps me :)
Yes. You can use progress bar.
You can use location Locationmanager and LocationListener Model. In this model you will be given with all the callbacks you need.
You can use GPS when you have no internet connection, and you can use location search (by any method you'd like) when you have internet connection. However, your request to enter the location name, then find its coordinates is impossible to do if you have no internet connection unless you keep a DB of all location names and their coordinates on your device, which is only possible if you make a rather short list of specific locations, a few countries at most.

How can I keep track of a "like" system on android?

I am currently making an android app for a friend who is a photographer where he will display his images in a RecyclerView. We would like to have sort of like a "like" feature where they can like his pictures. My question is, how would I keep track of the "likes"? What I mean is, how can I make it so that if someone already liked it, they cannot exit the app, come back and like it again? I thought about adding a +1 every time there was a like to the image properties in a database, but how can I keep them from exiting the app, coming back, and liking it again? TIA!
your problem is just a matter of identity. To achieve your goal, you should have a way to identify every piece of the pictures and each of the person who will give up-votes to these pictures.
If you can identify different pictures and different users, you can achieve your goal by either of the following ways:
For each of the pictures store all the users that have liked it. And every time a user want to like a picture, you should check whether he is in this collection or not. Only add the identity of the user to this collection if he is not in this set which means he did not like this picture before
Or you can store all the pictures that are liked by the user.
Which way is better depends on your other use cases.
To identify your pictures you can just assign a distinct name for each of the picture.
So you can see the key problem it how to identify your users.
Since you do not provide a detailed use case of the like action, I will describe some general ideas.
If you have a server
If the user must login, you can identify your users by their login id
If your user do not need to login, you can use some other information to identify your user for example their device id, MAC address or other device-specific indentity.
If you do not have a server, then how can you identify all the users that use the same device? The only way I can come up with is that, you must implement a local user system and ask the user to log in before they want to like a photo.
If you have so signing in users my guess is that you can't. You could save on a hidden file on the device the ids of the photos the device "liked" but this can be easily deleted if the user deletes the apps cache files or uninstall/reinstall.
Not an android expert here, just mho
With login:
In your Database there are "User", "Image" and "User_like_image"
You just have to check if this user didnt already upvoted the image
without login:
You locally store the ID of every images he upvoted
A rough idea: with each item that can be liked store a list of ids that liked it on the server. Your like count is equals to the list length.
On each device generate a random device id token (UUID.randomUUID() is always a good candidate), persist it locally on the device (e.g. in SharedPreferences - wiping the app data will kill it but that can't be solved reliably) and send it to the server with each request.
The server can now
tell you whether you already liked an image which is nice to see on the device and
reject multiple likes from the same device
A simpler approach: store locally in e.g. SharedPreferences that you liked the item. Then behave nicely and don't send another like request to your server backend when you see that you already did. Can be abused because it relies no the client software to be nice but I doubt a small photographer app needs to care too much about that.
A more elaborate approach: require user accounts. That works accross devices and persists through app uninstalls. People that go far enough to create multiple accounts to vote multiple times can't be stopped anyways. The big downside is that people will most likely not want to have another account just to like some photos. Would not recommend if avoidable.
What I did to avoid having people like the same item twice was:
Have 2 states with the same button. If you clicked on "like" the button state changes to "Remove Like" Save the state of the button in shared prefs and check the state before a click is given.
Example:
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String ButtonText = button.getText().toString();
if(ButtonText.equals("Like"){
//code for Like
button.setText("Remove Like");
}
else{
//code for remove Like
button.setText("Like");
}
}
});

Android Osmdroid get poins of interest from own database

This is my first time using stackoverflow because I am really desperate to solve this issue.
I am developing an app that contains information about bus stops in my country (Google maps does not work if I try to go from X to Y on a bus) so I decided to do it myself. I already tracked every stop of many buses.
I show each bus stop as overlays in my osmdroid map view, I get this information from a internal database that as I said I collected the information and is not online.
What I want to do now, is to get the user's location (lat, long) and tell him/her the closets bus stops to him/her location. I already looked at Osmdroid bonuspack and the POI feature, but what I understood is that these places (restaurants, bus stops, hospitals, etc) are already on a server.
How can I implement a POI function on my application with local information. I would appreciate any help, this is something I want to do for my community.
Thank you everyone and sorry for my poor English. I am doing my best.
You already have the coordinates of bus stops in your database, and they are displayed in an overlay. You can also get the current users location. What you want to achieve is a matter of calculating the geographical distance between two points (the user's location and a bus stop).
You don't have to implement a suitable formula yourself, e.g. have a look at the GeoPoint class. There's a distanceTo(final IGeoPoint other) method. You can instantiate a GeoPoint with known coordinates or simply use Overlay methods.
You could also achieve the same thing by querying only the bus stops that are within a certain radius of the user's location (maybe have a look at the BoundingBox)
If you want to use libraries like the BonusPack, look at the provider implementations. You could simply write your own provider for your bus stops. Have a look at e.g. this one.
> How can I implement a POI function on my
> application with local information
I assume that your question is about "how to render busstops on local device" and not "how to query my local database" and not "how to do some server-side support."
If you want to render the busstops on you local android device you can use osmbonuspack
which contain an example app that shows how to render interactive poi-s.
Unfortunately currently there is no precompiled osmbonuspack aar at jcenter/mavencentral so you have to include the sources as a local subdirectory of your project.

Stop form data being remembered

I have an android app, and i open webViews within it. now if someone types something into a textbox within my webView, the next time it is opened, it shows the suggestions (what the previous user typed).
How can i stop my webViews from storing the previous users entries?
The only way i can get rid of them is to delete all the data from my app, but i store other things in here, so dont want to delete all the data for my app.
Thanks in advance
try this
webview.getSettings().setSaveFormData(false);
here is full explanation
http://roysutton.com/2012/02/21/preventing-auto-fill-in-android-webview/

Categories

Resources