我无法成功在我的地图上放置一个自定义的居中叠加项目。它总是出现在底部和中间的中心。这是我的代码:
------------我的叠加项目类-------------
public class EditionThumbOverlayItem extends OverlayItem {
public EditionThumbOverlayItem(GeoPoint aGeoPoint, Resources resources) {
super("", "", aGeoPoint);
Drawable pinThumbDrawable = resources.getDrawable(R.drawable.pin_thumb);
pinThumbDrawable.setBounds(pinThumbDrawable.getIntrinsicWidth() * (-2 / 5),
pinThumbDrawable.getIntrinsicHeight() * (-2 / 5), pinThumbDrawable.getIntrinsicWidth() * 3 / 5,
pinThumbDrawable.getIntrinsicHeight() * 3 / 5);
setMarker(pinThumbDrawable);
}
}
-------------我的逐项叠加类-----------------
public class PinThumbOverlay extends ItemizedOverlay<OverlayItem> {
// Only one item can be set on this overlay
private OverlayItem mEditionThumb;
public PinThumbOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
super(pDefaultMarker, pResourceProxy);
}
@Override
public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
return false;
}
@Override
protected OverlayItem createItem(int arg0) {
return mEditionThumb;
}
@Override
public int size() {
if (mEditionThumb == null) {
return 0;
} else {
return 1;
}
}
public void addOverlayItem(OverlayItem overlay) {
mEditionThumb = overlay;
populate();
}
public void removeOverlayItem() {
mEditionThumb = null;
populate();
}
}
------------------逐项叠加创建------------------
DefaultResourceProxyImpl defaultResouceProxyImpl = new DefaultResourceProxyImpl(getApplicationContext());
Drawable defaultPinEdition = getResources().getDrawable(R.drawable.pin_thumb);
mPinThumbOverlay = new PinThumbOverlay(defaultPinEdition, defaultResouceProxyImpl);
mMapView.getOverlays().clear();
mMapView.getOverlays().add(mPinThumbOverlay);
-------------------叠加项目创建--------------
EditionThumbOverlayItem editionThumb = new EditionThumbOverlayItem(new GeoPoint(mCurrentUserLocation),
getResources());
mPinThumbOverlay.addOverlayItem(editionThumb);
注意:我使用 osmdroid 地图,而不是默认的 google map api。