我在我的 map 上显示一个 GroundOverlay,它的图像是用 Canvas 制作的,我在 Canvas 上画了一条弧线,但我遇到了一些问题:首先,应用程序在一段时间后崩溃(它给我一个 java.lang.OutOfMemoryError),它没有显示覆盖。我试过在叠加层的图片中放置一个白色背景并且它确实显示了它,所以我猜问题出在电弧上,但我不知道我做错了什么。有人知道吗?
Projection projection = map.getProjection();
Point point1 = projection.toScreenLocation(latlng1);
Point point2 = projection.toScreenLocation(latlng2);
float startAngle = (float) (Math.atan2(point1.y - point2.y,
point1.x - point2.x));
float sweepAngle = (float) (GenericNdData.getLateralTrajectory(
T_FplnType.ACTIVE.getId()).getSegment(i).getAngle());
float radius = FloatMath.sqrt((float) (Math.pow(
(point1.x - point2.x), 2) + Math.pow(
(point1.y - point2.y), 2)));
RectF rectangle = new RectF(point2.x - radius, point2.y
- radius, point2.x + radius, point2.y + radius);
Paint paint = new Paint();
paint.setARGB(250, 0, 255, 0);
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setFakeBoldText(true);
paint.setStrokeWidth(4f * Configuration.General.getScreenFactor());
paint.setStyle(Paint.Style.STROKE);
Bitmap arc = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(arc);
canvas.drawColor(0xFFFFFFFF);
canvas.drawArc(rectangle,
(float) (Math.toDegrees(startAngle)),
(float) (Math.toDegrees(sweepAngle)), false, paint);
GroundOverlay groundArc = map.addGroundOverlay(new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromBitmap(arc))
.position(latlng2, 10000));
提前致谢。
最佳答案
与标记一起使用时,存在与 BitmapDescriptorFactory.fromBitmap()
相关的已知内存泄漏问题。这可能是一个问题,但首先尝试:
GroundOverlay.remove()
先前在调用 GoogleMap.addGroundOverlay
之前添加的对象。
关于android - 在 Google Maps Android API v2 中显示使用 Canvas 制作的 GroundOverlay 的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16143122/