Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic Overlays slowing down Google Maps (Android 2.1) on Nexus One
    text
    copied!<p>I'm trying to create a dynamic <code>ItemizedOverylay</code> (please see the code below) on Google Maps (Android 2.1) on a Nexus One. </p> <p>In my <code>Activity</code> (that extends MapActivity) I'm creating a data thread that is receiving data from the network. A 'handler' is used to communicate the data from the receiving thread to map activity. This data contains the locations (lat, lon) of the markers that I want to overlay on my map. The location of each marker is dynamic (i.e., it changes every time I receive new data from the network.) <code>refreshItems(ArrayList&lt;OverlayItem&gt; newItems)</code> method in invoked inside the <code>handleMessage()</code> of the handler. There are around 11 markers in the ArrayList that is passed to <code>refreshItems</code></p> <p>I can see the markers overlayed on the map. However, I've two issues:</p> <ol> <li><p>The old markers are not removed from the map. After a while I see a trail of markers. </p></li> <li><p>The map doesn't respond to any touch commands. I cannot move the map or zoom in or zoom out. After a while I see a system warning that my app is not responding (wait/close?) message. </p></li> </ol> <p>Any idea what's wrong here ? </p> <p>Thanks. </p> <pre><code> public class MyItemizedOverlay extends ItemizedOverlay&lt;OverlayItem&gt; { private ArrayList&lt;OverlayItem&gt; overlayItems; public CoTItemizedOverlay(Drawable defaultMarker) { super(boundCenter(defaultMarker)); overlayItems = new ArrayList&lt;OverlayItem&gt;(); populate(); } public void addNewItem(GeoPoint location, String markerText, String snippet) { overlayItems.add(new OverlayItem(location, markerText, snippet)); populate(); } public void removeItem(int index) { overlayItems.remove(index); populate(); } public void refreshItems(ArrayList&lt;OverlayItem&gt; newItems) { // remove all existing items for (int i = 0; i &lt; cotoverlayItems.size(); i++) { overlayItems.remove(i); } // copy all the items if (newItems != null &amp;&amp; cotoverlayItems.size() == 0) { overlayItems.addAll(newItems); } populate(); } @Override protected OverlayItem createItem(int index) { return overlayItems.get(index); } @Override public int size() { return overlayItems.size(); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload