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();
)
Asked
Active
Viewed 304 times
0

Ashwin Nirmale
- 443
- 4
- 13

Costin
- 194
- 1
- 2
- 16
-
This would help you resolve your problem : https://stackoverflow.com/questions/30569854/adding-multiple-markers-in-google-maps-api-v2-android – Karan Mehta Jan 16 '20 at 09: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 Jan 16 '20 at 14:02
1 Answers
0
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!

Makzimalist
- 53
- 1
- 6