android path 画虚线,android – 绘制虚线(…)路径而不是一条线(________)

现在,下面是我在地图中绘制地理位置之间路径的代码.这完全没问题.我想要实现的不是画一条线,而是用iPhone中的点(.)显示这条路径.我想它就像这个gp1 ……… gp2而不是像gp1______gp2一样画一条直线.

我已经尝试了几乎所有的选择,但仍然没有成功,任何人都可以帮我解决这个问题?

private void drawPath(List geoPoints, int color) {

List overlays = objMapView.getOverlays();

int loopcount = geoPoints.size() - 1;

for (int i = 0; i < loopcount; i++) {

GeoPoint p1 = (GeoPoint) geoPoints.get(i);

GeoPoint p2 = (GeoPoint) geoPoints.get(i + 1);

MyPathOverLay p = null;

/**** Marking the start and end of the trailpath ****/

if (i == 0) {

Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.greenflag);

p = new MyPathOverLay(p1, p2, 0xFFFF0000, true, false, bmp);

} else if (i == loopcount - 1) {

Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.redflag);

p = new MyPathOverLay(p1, p2, 0xFFFF0000, false, true, bmp);

} else {

p = new MyPathOverLay(p1, p2, 0xFFFF0000, false, false, null);

}

overlays.add(p);

}

}

public class MyPathOverLay extends Overlay {

private GeoPoint gp1;

private GeoPoint gp2;

private int color;

Boolean isFirstPOI;

Boolean isLastPOI;

AudioMap audioMap;

Bitmap bmp;

public MyPathOverLay(GeoPoint gp1, GeoPoint gp2, int color,Boolean first, Boolean last,Bitmap bitMap) {

this.gp1 = gp1;

this.gp2 = gp2;

this.color = color;

this.isFirstPOI= first;

this.isLastPOI = last;

this.bmp = bitMap;

}

@Override

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

Projection projection = mapView.getProjection();

Paint paint = new Paint();

Point point = new Point();

projection.toPixels(gp1, point);

paint.setColor(color);

Point point2 = new Point();

projection.toPixels(gp2, point2);

paint.setStrokeWidth(5);

paint.setAlpha(120);

canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);

//---translate the GeoPoint to screen pixels---

Point screenPts = new Point();

mapView.getProjection().toPixels(gp1, screenPts);

//---translate the GeoPoint to screen pixels---

Point screenPts1 = new Point();

mapView.getProjection().toPixels(gp2, screenPts1);

if(isFirstPOI == true){

canvas.drawBitmap(bmp,screenPts.x-20,screenPts.y-40, null);

}

else if(isLastPOI == true) {

canvas.drawBitmap(bmp,screenPts1.x-20,screenPts1.y-35, null);

}

super.draw(canvas, mapView, shadow);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值