Android OverlayItem.setMarker(): Change the marker

2020-08-26 15:25发布

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);

2条回答
Anthone
2楼-- · 2020-08-26 15:41

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.

查看更多
乱世女痞
3楼-- · 2020-08-26 15:56

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);
查看更多
登录 后发表回答