Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add 1000's Markers to android Googlemap

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.

like image 655
Hector Avatar asked Jul 24 '13 11:07

Hector


1 Answers

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.

like image 139
MaciejGórski Avatar answered Sep 28 '22 01:09

MaciejGórski