gpt4 book ai didi

android - 在 map View 中绘制透明的圆圈

转载 作者:行者123 更新时间:2023-11-29 14:01:58 25 4
gpt4 key购买 nike

我有 mapview 和 Overlay 的问题。

每次更改 GPS 位置时,我都必须在 map 上画一个圆圈。我在扩展覆盖的覆盖类中使用了绘制方法。问题是我必须以透明方式绘制这些圆圈,但是当圆圈在交点处相互重叠时,颜色会有所不同,因为存在 alpha 总和。

我该如何解决?

这是我的覆盖类:

public class ImpactOverlay extends Overlay {

private static int CIRCLERADIUS = 0;
private GeoPoint geopoint;
private int myCircleRadius;
Point point = new Point();
Paint circle = new Paint(Paint.ANTI_ALIAS_FLAG);
private long systemTime= -1 ;



public ImpactOverlay(GeoPoint point, int myRadius) {

geopoint = point;
CIRCLERADIUS = myRadius; // assegna raggio del cerchio
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {

// Transfrom geoposition to Point on canvas
Projection projection = mapView.getProjection();
projection.toPixels(geopoint, point);

// the circle to mark the spot
circle.setColor(Color.parseColor("#88ff0000"));
circle.setAlpha(122); // trasparenza

myCircleRadius = metersToRadius(CIRCLERADIUS, mapView,
(double) geopoint.getLatitudeE6() / 1000000);

canvas.drawCircle(point.x, point.y, myCircleRadius, circle);

}



public static int metersToRadius(float meters, MapView map, double latitude) {
return (int) (map.getProjection().metersToEquatorPixels(meters) * (1 / Math
.cos(Math.toRadians(latitude))));
}

@Override
/* Implementa il doppio tap per eseguire zoom sulla mappa */
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if ((System.currentTimeMillis() - systemTime) < 250) {
mapView.getController().zoomIn();
}
systemTime = System.currentTimeMillis();
break;
}

return false;
}
}

最佳答案

        CircleOptions circle = new CircleOptions();
circle.center(new LatLng(latitude, longitude))
.radius(1500)//in meters
.strokeColor(Color.BLUE)//border color
.strokeWidth(3.0f)//border width
.fillColor(0x200000ff);//inside circle
googleMap.addCircle(circle);//GoogleMap googleMap(initialize accordingly)

关于android - 在 map View 中绘制透明的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9065597/

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