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

2

8

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);
Grishilda answered 21/9, 2011 at 19:33 Comment(3)
have you found a solution for this? I'm facing the same issue. calling setMarker() with a specific drawable makes the icon invisible...Lobel
You have to specify the bounding rectangle using setBounds()Grishilda
that indeed works, you should answer the question ;)Lobel
G
11

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);
Grishilda answered 11/5, 2012 at 13:5 Comment(0)
F
0

I believe this would work:

public void addOverlay(final OverlayItem overlay)
    {
        creditOverlay.add(overlay);
        populate();
        boundCenter(customMarker);
    }

You will have to call boundCenter or boundCenterBottom while adding overlay in map overlay list. In SetMarker() just set the custom maker.

Flitting answered 1/10, 2011 at 7:47 Comment(1)
This will cause all the items to use the same marker, unless the method is changed to: `addOverlay(OverlayItem, Drawable)Grishilda

© 2022 - 2024 — McMap. All rights reserved.