我与 OSMdroid 合作。我扩展了 Overlay 类,并根据需要覆盖了 draw 方法。而且我在放置标记时遇到了问题。当我第一次显示它们时,它们的位置错误。但是当我开始缩放时,它们会移动,并且经过几次缩放后,它们的定位是正确的。
这是我的代码:
protected final Rect mRect = new Rect();
protected Point mScreenPts = new Point();
@Override
protected void draw(Canvas c, MapView osmv, boolean shadow) {
Projection pj = osmv.getProjection();
synchronized (mInternalItemList) {
if (shadow && !mInternalItemList.isEmpty()) {
for(int i = 0; i < mInternalItemList.size(); i++) {
CustomizedItem customized = mInternalItemList.get(i);
pj.toMapPixels(new GeoPoint(customized.getLatitude(),
customized.getLongitude()), mScreenPts);
boundToHotspot(customized.getDrawable(), HotspotPlace.LOWER_LEFT_CORNER);
Drawable draw = customized.getDrawable();
draw.copyBounds(mRect);
draw.setBounds(mRect.left + mScreenPts.x, mRect.top + mScreenPts.y,
mRect.right + mScreenPts.x, mRect.bottom + mScreenPts.y);
draw.draw(c);
draw.setBounds(mRect);
}
}
}
}