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 に答える