Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Using the ItemizedOverlay and OverlayItem

MIME-Version: 1.0
Received: by 10.151.149.14 with SMTP id b14mr153208ybo.7.1219681776774; Mon, 
	25 Aug 2008 09:29:36 -0700 (PDT)
Date: Mon, 25 Aug 2008 09:29:36 -0700 (PDT)
X-IP: 84.92.169.141
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) 
	Gecko/2008052906 Firefox/3.0,gzip(gfe),gzip(gfe)
Message-ID: <98d3c356-15a0-4891-bf56-f2d883fa1c69@l42g2000hsc.googlegroups.com>
Subject: Using the ItemizedOverlay and OverlayItem
From: Reto <reto.me...@gmail.com>
To: Android Developers <android-developers@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

I've been trying to use the ItemizedOverlay and OverlayItem classes in
the 0.9 Beta to simulate map markers but have been having some
problems getting it to display on the map.

Once I've implemented my own ItemizedOverlay (and overriden
createItem), creating a new instance of my class seems to work (I can
extract OverlayItems from it) but adding it to the overlay list for
one of my maps doesn't seem to do anything.

I've included the code for adding the ItemizedOverlay to the map, and
the ItemizedOverlay implementation itself is also included. Have I
done something wrong or is this functionality not yet available?

// Add the ItemizedOverlay to the Map
private void addItemizedOverlay() {
  Resources r = getResources();
  mapView = (MapView)findViewById(R.id.map_view);
  List<Overlay> overlays = mapView.getOverlays();

  MyItemizedOverlay markers = new
MyItemizedOverlay(r.getDrawable(R.drawable.icon));
  overlays.add(markers);

  OverlayItem oi = markers.getItem(0);
  markers.setFocus(oi);
  mapView.postInvalidate();
}

Where MyItemizedOverlay is defined as:

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
  public MyItemizedOverlay(Drawable defaultMarker) {
    super(defaultMarker);
    populate();
  }

  @Override
  protected OverlayItem createItem(int index) {
    Double lat = (index+37.422006)*1E6;
    Double lng = -122.084095*1E6;
    GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());

    OverlayItem oi = new OverlayItem(point, "Marker", "Marker Text");
    return oi;
  }

  @Override
  public int size() {
    return 5;
  }