views:

24

answers:

1

Hello, I have the following code and the markers are not appearing on the map at all!

private class SitesOverlay extends ItemizedOverlay<pfOverlayItem> {

    private List<pfOverlayItem> items=new ArrayList<pfOverlayItem>();
    //private   PopupPanel panel=new PopupPanel(R.layout.popup);

    public SitesOverlay() {
        super(null);

        items = mainOverlayArray;

        populate();

    }

    @Override
    protected pfOverlayItem createItem(int i) {
        return(items.get(i));
    }

    @Override
    public void draw(Canvas canvas, MapView mapView,
                                        boolean shadow) {
        super.draw(canvas, mapView, shadow);

    }


    @Override
    public int size() {

        return(items.size());

    }



    private Drawable getMarker(int resource) {
        Drawable marker=getResources().getDrawable(resource);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                                            marker.getIntrinsicHeight());
        boundCenter(marker);

        return(marker);
    }
}

mainOverlayArray is full of pfOverlayItem's and the code for that class is

public class pfOverlayItem extends OverlayItem {
private String coolText;

public String getcoolText() {
    return coolText;
}

public void setcoolText(String coolText) {
    this.coolText = coolText;
}

public pfOverlayItem(GeoPoint point, String title, String snippet) {
    super(point, title, snippet);
    // TODO Auto-generated constructor stub
}

}

I also set the marker outside of this after processing an XML file...

 ArrayList<pfOverlayItem> overArray = myXMLHandler.getOverlayArray();
                mainOverlayArray = overArray;
                pfOverlayItem tempOver = null;
                Drawable marker = getResources().getDrawable(R.drawable.icon);
                for (int i = 0; i < mainOverlayArray.size(); i++) {
                    tempOver = mainOverlayArray.get(i);
                    tempOver.setMarker(marker);
                }

                sites=new SitesOverlay();
                myMapView.getOverlays().add(sites);
                myMapView.invalidate(); [/code]
+1  A: 

It looks as though you're starting from one of my many sample Google Map applications. Your code as shown here is incomplete (e.g., according to the code here, you never create any OverlayItem instances).

My recommendation is you roll back to one of the samples I link to above and start modifying from there, or you start trying to figure out which of your methods are getting called and which are not.

CommonsWare
Yes thanks. I did start with the sample but have replaced the OverlayItem with my own as I wanted to extend it further. What bit makes you think it is never called?I have a method that creates an array (mainOverlayArray) full of pfOverlayItems
Lee Armstrong
@Lee Armstrong: populating `mainOverlayArray` is not in the code you show above.
CommonsWare
I see. I just did a tested with another of your examples and it works.....this is the one that uses "public SitesOverlay(Drawable marker)". It appears that the marker is not being pulled through on my custom object, am I missing anything in my second code block that extends OverlayItem?
Lee Armstrong
After playing around I was missing this line....marker.setBounds(0, 0, marker.getIntrinsicWidth(),marker.getIntrinsicHeight());After adding this it works! Why is this?
Lee Armstrong
@Lee Armstrong: That is one of those calls that I have never fully understood, mostly because I have not played much with the 2D graphics API.
CommonsWare
Ok thanks, I will do some digging!
Lee Armstrong