Note that there are some explanatory texts on larger screens.

plurals
  1. POOSMDroid Overlays Multiple Static and one Dynamic
    text
    copied!<p>In my application, I already have some static overlays on the map, and one dynamic which changes it's place when GPS coords change.</p> <p>My problem is that, when the GPS coords change, I have to clear the dynamic overlay and create a new one, but when I do that, it clears all the overlays, using:</p> <pre><code>mapView.getOverlays().clear(); </code></pre> <p>So, I'm trying to find the better way to do it.</p> <p>Clear all the overlays and then place them again on the map (memory consuming) or can I clear a specific overlay?</p> <p>Thanks</p> <p><strong>Edit:</strong></p> <p><em>This is the dynamic marker:</em></p> <pre><code>@Override public void onLocationChanged(Location location) { Log.d("Location", "onLocationChanged with location " + location.toString()); mLatitude = (int) (location.getLatitude() * 1E6); mLongitude = (int) (location.getLongitude() * 1E6); GeoPoint gpt = new GeoPoint(mLatitude,mLongitude); markerYou.clear(); markerYou.add(new OverlayItem(getString(R.string.markerYou), getString(R.string.markerYouDescription), gpt)); mMyLocationOverlay = new ItemizedIconOverlay&lt;OverlayItem&gt;(markerYou, new ItemizedIconOverlay.OnItemGestureListener&lt;OverlayItem&gt;() { @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Toast.makeText(ShowMap.this, getString(R.string.markerYouDescription), Toast.LENGTH_SHORT).show(); return true; } @Override public boolean onItemLongPress(final int index, final OverlayItem item) { Toast.makeText(ShowMap.this, getString(R.string.markerYouDescription),Toast.LENGTH_SHORT).show(); return true; } }, mResourceProxy); mapView.getOverlays().clear(); mapView.getOverlays().add(mMyLocationOverlay); mapView.invalidate(); mapController.setCenter(gpt); } </code></pre> <p><em>This is the function that places the static markers:</em></p> <pre><code>public void putPlacesOfInterest(){ this.dh = new DataHelper(ShowMap.this); List&lt;Pontos&gt; list = this.dh.selectAll(); for(Pontos p : list){ markerPlaces.add(new OverlayItem(p.getName().toString(), p.getName().toString(), new GeoPoint(p.getLat(), p.getLng()))); } mMyLocationOverlay = new ItemizedIconOverlay&lt;OverlayItem&gt;(markerPlaces, new OnItemGestureListener&lt;OverlayItem&gt;() { @Override public boolean onItemLongPress(int index, OverlayItem item) { Toast.makeText(ShowMap.this, "Item " + item.mTitle, Toast.LENGTH_LONG).show(); return true; } @Override public boolean onItemSingleTapUp(int index, OverlayItem item) { Toast.makeText(ShowMap.this, "Item " + item.mTitle, Toast.LENGTH_LONG).show(); return true; } }, mResourceProxy); mapView.getOverlays().add(mMyLocationOverlay); mapView.invalidate(); } </code></pre>
 

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