0

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();)

2
  • This would help you resolve your problem : stackoverflow.com/questions/30569854/… Commented 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) Commented Jan 16, 2020 at 14:02

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.