大家好,我尝试使用自定义MapField在地图上显示几个loacations。我可以在地图上显示位置。但无法移动图像,也无法放大和缩小。我尝试使用自定义MapField,但它仍然不适合我.. 这是我的代码
class CustomMapField extends MapField
{
Bitmap mIcon;
XYRect mDest;
public void moveTo(Coordinates coordinates)
{
super.moveTo(coordinates);
mDest = null;
}
protected void paint(Graphics graphics)
{
super.paint(graphics);
if (null != mIcon)
{
if (null == mDest)
{
XYPoint fieldOut = new XYPoint();
convertWorldToField(getCoordinates(), fieldOut);
int imgW = mIcon.getWidth();
int imgH = mIcon.getHeight();
mDest = new XYRect(fieldOut.x - imgW / 2,fieldOut.y - imgH, imgW, imgH);
}
graphics.drawBitmap(mDest, mIcon, 0, 0);
}
}
}
答案 0 :(得分:1)
放大和缩小我使用了这个 -
public boolean keyChar(char key, int status, int time)
{
if(key=='i')
{
mMapField.setZoom(Math.max(mMapField.getZoom() - 1,mMapField.getMinZoom()));
}
else if(key=='o')
{
mMapField.setZoom(Math.min(mMapField.getZoom() + 1,mMapField.getMaxZoom()));
}
return super.keyChar(key, status, time);
}