I've been searching for some time, but did not manage to find any useful posts, so I wanted to ask here. I am developing an app that retreives latitudes and longitudes plus some other data from a server and add the markers on a map, according to the data received. My question is if I can add a function to the app, so that if in the database it's added another row (latitude+longitude), to dinamically add the marker on the map from my app without using a refresh button calling OnMapReady every time(my addMarker(); is there, so right now I implemented a button to call that again, resulting in querying the DB and add all the markers again after a mMap.clear();)
-
This would help you resolve your problem : stackoverflow.com/questions/30569854/…Karan Mehta– Karan Mehta2020-01-16 09:49:54 +00:00Commented Jan 16, 2020 at 9:49
-
I have the markers added on my map. My question is how I can change the code to observe all the time the database and to auto-add another marker if another set of lat-long is added into DB. I know how to add them, I do not know how to maintain a constant link to DB to observe the changes (if i erase a row in the table to clear the marker etc, without manually pressing any button)Costin– Costin2020-01-16 14:02:42 +00:00Commented Jan 16, 2020 at 14:02
Add a comment
|
1 Answer
I would do it with Rx and listening/observing your database. In your view you could subscribe on this Flowable/Observable with something like below. I use a Room DataBase. If you are new top this topic search here for answers like how to listern to room database changes or simply google tutorials
@Query("SELECT * FROM yourMapDatabase")
abstract fun observeAll(): Flowable<List<LatLng>>
If you are listening to a backend Database. you can do the same and simply write your requested Data into your own database and update your view.
Hope this helps a bit, if you have further questions, shot!