1

我正在尝试在圆圈内画几个圆圈并将它们显示在 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;
        }
    }

下面是我的通讯器的截图,你可以清楚地看到,它不是在圆圈的中心——

在此处输入图像描述

任何人都可以提供一些想法吗?

4

1 回答 1

1

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

于 2013-02-02T23:32:39.810 回答