Several overlay elements in android

I seem to have a problem using ItemizedOverlay and OveralyItems.

I can get the first overlayItem file that appears on the map, but not after it.

Sample code is included: http://www.anddev.org/multiple_overlay_items-t12171.html

A quick overview here:

public class Markers extends ItemizedOverlay { private Context ctx; private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); public Markers(Drawable defaultMarker, Context cont) { super(boundCenterBottom(defaultMarker)); this.ctx = cont; // TODO Auto-generated constructor stub } @Override protected OverlayItem createItem(int i) { // TODO Auto-generated method stub return mOverlays.get(i); } @Override public boolean onTap(GeoPoint p, MapView mapView) { // TODO Auto-generated method stub return super.onTap(p, mapView); } @Override protected boolean onTap(int index) { // TODO Auto-generated method stub Toast.makeText(this.ctx, mOverlays.get(index).getTitle().toString()+", Latitude: "+mOverlays.get(index).getPoint().getLatitudeE6(), Toast.LENGTH_SHORT).show(); return super.onTap(index); } @Override public int size() { // TODO Auto-generated method stub return mOverlays.size(); } public void addOverlay(OverlayItem item) { mOverlays.add(item); setLastFocusedIndex(-1); populate(); } public void clear() { mOverlays.clear(); setLastFocusedIndex(-1); populate(); } } 

Examples of using:

 Markers usersMarker = new Markers(user,overview.this); GeoPoint p = new GeoPoint((int) (lat * 1E6),(int) (lon * 1E6)); OverlayItem item = new OverlayItem(p,userData[0],userData[3]); item.setMarker(this.user); usersMarker.addOverlay(item); 

The first marker appears on the map, but if I add more, they will not appear? Is there a problem with the populate () method? I tried calling it manually after adding all the markers, but that still didn't help. Please, if you know what might be wrong, say it.

+1
source share
3 answers

I finally found the answer. I am ashamed to admit this, but the problem is not in the details, not in the drawing, but they do not see them on the screen .... The places for two objects should have been almost the same ... but one of them was calculated with an error and moved halfway around the world.

So I never bothered to watch or zoom out ... when I did this, I found that my other marker is sitting somewhere in the Barents Sea :) Thanks to everyone who tried to help me ... oh, and the code above working:)

+1
source

check out this example project . add multiple addOverlay () s to ur several times

+5
source

I have working code that looks almost the same as yours, except that I do not call setLastFocusedIndex in my addOverlay function. Try commenting on this and see if it works.

+1
source

All Articles