Android Overlay 添加本地位置图标
代码如下:
public class MyOverlay extends Overlay{
private final int mRadius = 5;
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// TODO Auto-generated method stub
Projection projection = mapView.getProjection();
if (shadow == false) {
//获得当前的位置
GeoPoint geoPoint;
geoPoint = new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
// 把位置转换为屏幕像素
Point point = new Point();
projection.toPixels(geoPoint, point);
RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
// 设置paint
Paint paint = new Paint();
paint.setARGB(250, 255, 0, 0);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
Paint backPaint = new Paint();
backPaint.setARGB(175, 50, 50, 50);
backPaint.setAntiAlias(true);
RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3*mRadius, point.x + 65, point.y + mRadius);
// 绘制标记
canvas.drawOval(oval, paint);
canvas.drawRoundRect(backRect, 5, 5, backPaint);
canvas.drawText("Here I Am", point.x + 2*mRadius, point.y, paint);
}
super.draw(canvas, mapView, shadow);
}
}
调用时用:
overlays.add(new MyOverlay());
结果如图: