Add 1000's Markers to android Googlemap
Asked Answered
S

2

6

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.

Sill answered 24/7, 2013 at 11:43 Comment(4)
code.google.com/p/android-maps-extensionsMicroampere
Have u tried AsyncTask..Roz
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()Sill
map extensions are superb, please add this as a proper answer as it deserves MUCH more credit. Thank you Lalit Poptani.Sill
G
9

One possible way is to only add Markers 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 Markers. 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.

Gebler answered 24/7, 2013 at 20:9 Comment(3)
OhMyGod thanks for the link to the clustering extension, I though it only existed for the JS API.Frick
@thibaultd This is code I wrote. There is another approach here: github.com/twotoasters/clusterkrafSmolensk
@Gebler I don't see a method setClustering for GoogleMap object. Is this not there in the new library?Haply
C
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.

Countervail answered 24/7, 2013 at 11:48 Comment(1)
thanks for taking the time to answer my question. However the "Spatial Lite" link is giving me a 404Sill

© 2022 - 2024 — McMap. All rights reserved.