5

I want to show markers on the map in a manner similar to this example, but I have more markers and I want to use "native" Google Map.

So far I have found only 1 library that looked like capable of doing this: android-maps-utils. But after testing I discovered that it has serious performance problems when there are about 35000 markers. (and even java.lang.OutOfMemoryError). So I'm wondering which other options are out there. Rolling my own solution from scratch is probably the last thing I want to do.

I guess, that library isn't going to be usable at all with very large marker counts, because it keeps them all in RAM. It might be better to filter out currently invisible markers while reading them from a file, for example, and do it after each camera movement. (Reading 35k pairs of double from binary file via DataInputStream was pretty fast, so this isn't a big deal right now. And I guess this can be accelerated even further.) Also, I can prepare preprocessed sets of clusters for different zoom levels in different files, because markers are not going to change frequently.
But implementing this from scratch (especially — proper clustering) looks like a lot of work. Maybe I'm missing something that already does it?

Update

I tried using android-maps-extensions for this purpose. It works better, but it keeps all markers in memory too, and when displaying about 35k markers it results in ~20MB memory consumption when completely zoomed out, and ~24MB when zoomed in. Another ~7MB and there will be crashes... So I think I need to keep as little data in RAM as possible. Is there a library that works like that?

Display Name
  • 8,022
  • 3
  • 31
  • 66
  • 1
    cluster your markers: https://code.google.com/p/android-maps-extensions/ – Blundell Feb 28 '14 at 21:26
  • @Blundell Thank you. This library performs much better! Although it's not ideal, I think it will suffice for my needs at least for some time. – Display Name Mar 01 '14 at 09:17
  • 1
    @SargeBorsch Can you share your thoughts on what you don't like about Android Maps Extensions? There is also another library called [Clusterkraf](https://github.com/twotoasters/clusterkraf), but it's not actively developed anymore. – MaciejGórski Mar 01 '14 at 11:48
  • @MaciejGórski Hello. First, I must admit that the library is indeed really good. For the "don't like" part: first surprise was that there is no "bulk add" method that takes a collection of markers and adds them all at once. But maybe this won't give any speedup? I didn't look at the source code yet... Second, looks like the clustering algorithm uses a grid to split markers, and it sometimes causes a bit weird marker/cluster placement (I need to test more to prove or disprove this). And scrolling is not very smooth with 35k markers, but I guess this is a limitation of Google Maps too. – Display Name Mar 01 '14 at 12:00
  • @SargeBorsch I don't think there is a need for bulk adding. The lib uses `Handler` to postpone any calculations needed for clustering, so if you just loop yourself, you are good. Yes, the current clustering implementation is grid based. AME does not use threads (both AMU and Clusterkraf do use them), so some calculations could be done on background to improve scrolling, but I'm not sure if the improvement would be visible. Do you use `ClusteringSettings.addMarkersDynamically(true)`? – MaciejGórski Mar 01 '14 at 12:17
  • @MaciejGórski Yes, I do. Here is more complete code snippet: http://pastebin.com/zgp5Eyx4 – Display Name Mar 01 '14 at 12:24
  • @MaciejGórski I've measured RAM usage and updated the question, just in case you are interested. – Display Name Mar 02 '14 at 09:58
  • @SargeBorsch If you don't want to keep all the data in memory, simply add `Marker`s only when they are on the screen. – MaciejGórski Mar 02 '14 at 18:20
  • @MaciejGórski yes, but when zoomed out it still means that I need to add very much of them... I will try clustering markers "offline" and then adding visible markers (or clusters). – Display Name Mar 16 '14 at 22:02

0 Answers0