I have the same problem as when using android-mapviewballoons . I need half a day to find a solution. Here is my fix:
On your CustomItemizedOverlay let me make an overlay in boundCenterBottom
public CustomItemizedOverlay(Drawable defaultMarker, MapView mapView) { super(boundCenterBottom(defaultMarker), mapView); c = mapView.getContext(); }
And in your Map Activity, when you create a marker, you can do a trick like this (thanks to Cyril Mottier for his Polaris mapview library ):
drawable = MapViewUtils.boundMarkerCenterBottom(getResources().getDrawable(R.drawable.map_pin_holed_violet));
MapViewUtils obtained from the Polaris library. Here's the boundMarkerCenterBottom function:
public static Drawable boundMarkerCenterBottom(Drawable marker) { return boundMarker(marker, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); } public static Drawable boundMarker(Drawable marker, int gravity) { if (marker == null) { return null; } final int width = marker.getIntrinsicWidth(); final int height = marker.getIntrinsicHeight(); if (width < 0 || height < 0) { throw new IllegalStateException("The given Drawable has no intrinsic width or height"); } int left, top; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: left = 0; break; case Gravity.RIGHT: left = -width; break; case Gravity.CENTER_HORIZONTAL: default: left = -width / 2; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: top = 0; break; case Gravity.CENTER_VERTICAL: top = -height / 2; break; case Gravity.BOTTOM: default: top = -height; break; } marker.setBounds(left, top, left + width, top + height); return marker; }
source share