gpt4 book ai didi

java - 在外接圆的中心显示标记

转载 作者:行者123 更新时间:2023-11-30 03:47:50 26 4
gpt4 key购买 nike

我正在尝试绘制几个圆圈内的圆圈 并在 Google map 上显示它们。当前位置应该在所有圆圈的中心。表示在圆圈中间。

一切正常。但不知何故,我的标记没有显示在所有圆圈的中心。标记大小为 36 x 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

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

最佳答案

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

关于java - 在外接圆的中心显示标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14667560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com