amirpiri / android-maps-extensions

Automatically exported from code.google.com/p/android-maps-extensions
0 stars 0 forks source link

Fill from background thread #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Will be great if would be possible to fill all markers from background thread 
to avoid blocking UI thread during load and fill data. Now maps extension use 
internal collection to keep all markers (or others map object). For example if 
I want to create markers from downloaded JSON file I must download and parse 
JSON in background thread and put all POIs to the same collection and then back 
in UI thread fill it to the map. Much easy and memory save will be store it 
directly to the maps extensions internal collection and after all will be done 
only call same method with display all data on the map

Original issue reported on code.google.com by tomas.pr...@gmail.com on 10 Apr 2013 at 5:32

GoogleCodeExporter commented 8 years ago
Hello Tomas,

Can you post relevant code of what you want to achieve and proposition for API 
change?
I wouldn't want this lib API to drift too far away from the original library.

Some control questions:
How many markers do you want to add this way?
Are you using clustering with addMarkersDynamically set to true?

Original comment by maciek.g...@gmail.com on 10 Apr 2013 at 7:25

GoogleCodeExporter commented 8 years ago
It was only idea. I have about 5000 markers on the map and I'm using 
addMarkersDynamically. Now I make DB query in the background thread and them 
already on the UI thread iterate over all rows in the cursor add call 
addMarker(). It is relatively fast. I only think that maybe should be faster if 
will be possible call addMarker() also from background thread. But it require 
some additional method which must be called after all markers will be added to 
propagate changes to the map. Now it crash by ConcurrentModificationException.

I have also thought about the possibility to not load (from DB) all markers but 
only for square region around displayed area. But I don't know how to do it 
fast. Clear all markers after every move it is relatively slow. If I will only 
add new ones after every move it will make duplicates or it is handled?

Original comment by tomas.pr...@gmail.com on 12 Apr 2013 at 8:46

GoogleCodeExporter commented 8 years ago
The code is made to not call the original library unless necessary. So when you 
add 5000 markers, only a dozen or so are really created in the end.

I have just checked with LaunchTimeTestActivity available in demo project. For 
5000 markers with clustering and dynamic addition enabled it takes 180ms
This might be an issue of course, but I don't think adding synchronization to 
allow multiple threads access would decrease that.

One thing I can suggest is to add markers in packets using Handler. Take this 
as an example: 
https://github.com/mg6maciej/android-maps-v2-demo/blob/master/NewMapsDemo/src/pl
/mg6/newmaps/demo/AddMarkersInBackgroundExampleActivity.java

If you don't add all the markers, you can get some improvements, but you need 
to be careful not to add same marker twice.

Original comment by maciek.g...@gmail.com on 12 Apr 2013 at 8:10