在外接圆的中心显示标记

时间:2013-02-02 23:12:56

标签: java android android-mapview itemizedoverlay

我正在尝试在圈子中绘制几个圈子并在Google地图上显示它们。当前位置应位于所有圆圈的中心。意味着在圆圈中间。

一切都很好。但不知怎的,我的标记没有显示在所有圆圈的中心。标记大小为36 by 36

我试过很少的打击和试验,但仍然是同样的问题。有什么方法可以将标记放在所有外接圆的中心吗?我的代码有什么问题,因为它没有显示在圆圈的中心?可能是我画圆圈的方式不对吗?

@Override
    public void onLocationChanged(Location location) {
        if (location != null) {
        GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),
            (int) (location.getLongitude() * 1E6));

        mapController.animateTo(point);
        mapController.setZoom(15);

        if (mapOverlay == null) {
            mapOverlay = new MapOverlay(this, R.drawable.mark_blue);

            List<Overlay> listOfOverlays = mapView.getOverlays();
            listOfOverlays.add(mapOverlay);
        }

        mapOverlay.setPointToDraw(point);
        mapView.invalidate();
        }
    }

下面是我的MapOverlay类,其中我在圆圈中绘制圆圈

class MapOverlay extends Overlay {
    private GeoPoint pointToDraw;
    int[] imageNames = new int[6];
    private Point mScreenPoints;
    private Bitmap mBitmap;
    private Paint mCirclePaint;

    public MapOverlay(GPSLocationListener gpsLocationListener, int currentUser) {
        imageNames[0] = currentUser;
        imageNames[1] = R.drawable.tenm;
        imageNames[2] = R.drawable.twentym;
        imageNames[3] = R.drawable.thirtym;
        imageNames[4] = R.drawable.fourtym;
        imageNames[5] = R.drawable.fiftym;

        mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mCirclePaint.setColor(0x10000000);
        mCirclePaint.setStyle(Style.FILL_AND_STROKE);
        mBitmap = BitmapFactory.decodeResource(getResources(), imageNames[0]);
        mScreenPoints = new Point();
    }

    public void setPointToDraw(GeoPoint point) {
        pointToDraw = point;
    }

    public GeoPoint getPointToDraw() {
        return pointToDraw;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);
        mScreenPoints = mapView.getProjection().toPixels(pointToDraw, mScreenPoints);

        int totalCircle = 5;
        int radius = 40;
        int centerimagesize = 13;

        for (int i = 1; i <= totalCircle; i++) {
        canvas.drawCircle(mScreenPoints.x, mScreenPoints.y, i * radius, mCirclePaint);
        canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), imageNames[i]),
            ((mScreenPoints.x) + (i * radius)), (mScreenPoints.y), null);
        }

        canvas.drawBitmap(mBitmap, (mScreenPoints.x - (centerimagesize / 2)),
            (mScreenPoints.y - (centerimagesize / 2)), null);
        super.draw(canvas, mapView, shadow);

        return true;
        }
    }

下面是我的传播者的截图,你可以清楚地看到它,它不会出现在圈子的中心 -

enter image description here

有人能提出一些想法吗?

1 个答案:

答案 0 :(得分:1)

在我看来,标记图形的左上角位于圆圈的中心。因此,您需要通过从左上角到标记的实际点的位移来调整标记位置。我想这将是18水平和36垂直。