【发布时间】:2013-04-22 17:49:05
【问题描述】:
我在我的地图上显示了一个 GroundOverlay,它的图像是用画布制作的,我在画布上画了一个弧线,但我遇到了一些问题:首先,应用程序在一段时间后崩溃(它给我是一个 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));
提前致谢。
【问题讨论】:
-
这段代码在哪里调用?
-
在显示地图的 Fragment 中(不是 MapFragment,我自己制作的)
-
在 onResume 或类似的地方?我想知道这段代码是否被意外调用了多次。
-
哦,在每次有更新时调用的函数中(我的应用程序显示从另一个程序获取的信息)。基本上每次对另一个应用程序进行修改时,都会再次调用该函数,并且弧会发生变化。
标签: android google-maps android-canvas google-maps-android-api-2