I have a database containing a large number of hotspots I want to display (~20,000, spread over one country). Obviously adding all of these at once causes immense strain on the device, so I'm trying to find alternative solutions.
I am currently using an onCameraChange listener to be notified when the user has moved the app, then only loading hotspots which are in the visible area of the screen. However, if the user only moves the map by a small amount, duplicate hotspots will be added. Is Google Maps clever enough to not add a duplicate hotspot?
To try and avoid this I was calling clear() on the map every time the user moved, and then loading the hotspots again. However, if the user clicks on a hotspot to view the associated title, then the map centers on it, causing the map to move and clearing then readding the hotspot, which instantly hides the title.
What would be the optimal solution of dealing with this issue? Thanks
i would not "clear" and "readd" the markers but just hide them. Instead of adding the points, just set it to visible if is inside the visible area, set it not visible otherwise https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker#setVisible(boolean)
I would suggest you to explore marker clusters in this library: https://github.com/googlemaps/android-maps-utils