<p>Has anyone managed to use <code>ItemizedOverlays</code> in Android Beta 0.9? I can't get it to work, but I'm not sure if I've done something wrong or if this functionality isn't yet available. </p>

<p>I've been trying to use the <code>ItemizedOverlay</code> and <code>OverlayItem</code> classes. Their intended purpose is to simulate map markers (as seen in Google Maps Mashups) but I've had problems getting them to appear on the map.</p>

<p>I can add my own custom overlays using a similar technique, it's just the <code>ItemizedOverlays</code> that don't work.</p>

<p>Once I've implemented my own <code>ItemizedOverlay</code> (and overridden <code>createItem</code>), creating a new instance of my class seems to work (I can extract <code>OverlayItems</code> from it) but adding it to a map's <code>Overlay</code> list doesn't make it appear as it should.</p>

<p>This is the code I use to add the <code>ItemizedOverlay</code> class as an <code>Overlay</code> on to my <code>MapView</code>.</p>

<pre><code>// Add the ItemizedOverlay to the Map
private void addItemizedOverlay() {
  Resources r = getResources();
  MapView mapView = (MapView)findViewById(R.id.mymapview);
  List&lt;Overlay&gt; 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();
}
</code></pre>

<p>Where <code>MyItemizedOverlay</code> is defined as:</p>

<pre><code>public class MyItemizedOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
  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;
  } 
}
</code></pre>

[{'answer_id': 46766, 'author': 'eon', 'author_id': 2000, 'author_profile': 'https://Stackoverflow.com/users/2000', 'pm_score': 7, 'selected': True, 'text': '<p>For the sake of completeness I\'ll repeat the discussion on Reto\'s post over at the <a href="http://groups.google.com/group/android-developers/browse_thread/thread/36fe0648dabfe745#" rel="noreferrer">Android Groups here</a>.</p>\n\n<p>It seems that if you set the bounds on your drawable it does the trick:</p>\n\n<pre><code>Drawable defaultMarker = r.getDrawable(R.drawable.icon);\n\n// You HAVE to specify the bounds! It seems like the markers are drawn\n// through Drawable.draw(Canvas) and therefore must have its bounds set\n// before drawing.\ndefaultMarker.setBounds(0, 0, defaultMarker.getIntrinsicWidth(),\n    defaultMarker.getIntrinsicHeight());\n\nMyItemizedOverlay markers = new MyItemizedOverlay(defaultMarker);\noverlays.add(markers);\n</code></pre>\n\n<p>By the way, the above is shamelessly ripped from <a href="http://www.marcelp.info/2008/09/01/android-itemizedoverlay-demo/" rel="noreferrer">the demo at MarcelP.info</a>. Also, here is a <a href="http://androidguys.com/?p=1413" rel="noreferrer">good howto</a>.</p>\n'}, {'answer_id': 58889919, 'author': 'zahra salmaninejad', 'author_id': 11372789, 'author_profile': 'https://Stackoverflow.com/users/11372789', 'pm_score': 1, 'selected': False, 'text': '<p>try :</p>\n\n<pre><code>Drawable defaultMarker = r.getDrawable(R.drawable.icon);\n\ndefaultMarker.setBounds(0, 0, defaultMarker.getIntrinsicWidth(),\n    defaultMarker.getIntrinsicHeight());\n\nMyItemizedOverlay markers = new MyItemizedOverlay(defaultMarker);\noverlays.add(markers);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26362', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/822/']