I am developing a GoogleMap based android application.
I need to display 1000's of Markers on the map.
Currently I retrieve the Latitude and Longitude for each marker from an SQLite database loader and add the markers in the public void onLoadFinished(final Loader loader, final Cursor cursor)
method.
this approach gives a very bad user experience though, as the application does not respond while i add the Markers.
how can i add 1000's of markers to a googlemap and keep my application responsive?
as i have to add the markers to the map on the main UI thread.
Asked
Active
Viewed 2,477 times
6

Hector
- 4,016
- 21
- 112
- 211
-
4https://code.google.com/p/android-maps-extensions/ – Lalit Poptani Jul 24 '13 at 11:48
-
Have u tried AsyncTask.. – Juliousraj Jul 24 '13 at 12:03
-
i havent tried AsyncTask, however i dont think that will solve the issue as i still have to add the markers on the ui thread from within the onPostExecute() – Hector Jul 24 '13 at 12:06
-
map extensions are superb, please add this as a proper answer as it deserves MUCH more credit. Thank you Lalit Poptani. – Hector Jul 25 '13 at 06:52
2 Answers
9
One possible way is to only add Marker
s when they fall into visible region of the map.
You would actually have to move your calls to addMarker
from onLoadFinished
to onCameraChange
and in onLoadFinished
only create a list of data needed to create these Marker
s. In the simplest form this might be List<MarkerOptions>
.
Android Maps Extensions mentioned by Lalit Poptani in the comments above can handle that for you even if you don't want to use clustering. You simply leave your code like it is and only make a call like
googleMap.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));
after replacing Google Maps Android API v2 with this extensions lib.

MaciejGórski
- 22,187
- 7
- 70
- 94
-
OhMyGod thanks for the link to the clustering extension, I though it only existed for the JS API. – Thibault D. Jul 26 '13 at 20:41
-
1@thibaultd This is code I wrote. There is another approach here: https://github.com/twotoasters/clusterkraf – MaciejGórski Jul 27 '13 at 09:27
-
@MaciejGórski I don't see a method `setClustering` for `GoogleMap` object. Is this not there in the new library? – Gurupad Mamadapur Nov 20 '18 at 08:29
0
You can use Spatial Lite provider with geoserver to provide WMS maps. In android you can set a tile provider to consuming such tile maps.

Arnaldo Ignacio Gaspar Véjar
- 1,277
- 9
- 17
-
thanks for taking the time to answer my question. However the "Spatial Lite" link is giving me a 404 – Hector Jul 24 '13 at 12:04