Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android OverlayItem.setMarker(): Change the marker for one item

Trying to change the marker from an overlay item I noticed the setMarker() makes the item not visible. Here's the code sample.

//Create new marker
Drawable icon = this.getResources().getDrawable(R.drawable.marker);

//Set the new marker to the overlay
overlayItem.setMarker(icon);
like image 835
slybloty Avatar asked Sep 21 '11 19:09

slybloty


1 Answers

A bounding rectangle needs to be specified for the Drawable:

//Create new marker
Drawable icon = this.getResources().getDrawable(R.drawable.marker);

//Set the bounding for the drawable
icon.setBounds(
    0 - icon.getIntrinsicWidth() / 2, 0 - icon.getIntrinsicHeight(), 
    icon.getIntrinsicWidth() / 2, 0);

//Set the new marker to the overlay
overlayItem.setMarker(icon);
like image 102
slybloty Avatar answered Sep 28 '22 07:09

slybloty