两个地理点之间的绘制路径与来自资源的图像

时间:2013-11-26 19:24:37

标签: android maps draw

我需要两个地理位置之间的显示线但不仅仅是我需要使用一个来自资源的图像(R.drawable.line_image)。好吧,我可以画线或路径只是我不知道我如何使用图像。 (我发现很多例子,但都使用普通线,而不是图像)

Sombody很少帮助或这样的例子? THX

我的实际画线代码:

Paint paint;
   paint = new Paint();
   paint.setAntiAlias(true);
   paint.setStyle(Style.STROKE);
   paint.setStrokeWidth(7);
   Point pt1 = new Point();
   Point pt2 = new Point();
   Projection projection = (Projection) mapView.getProjection();

   projection.toPixels(start_, pt1);
   projection.toPixels(end_, pt2);
   canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, paint);

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案:

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

   Point pt1 = new Point();
   Point pt2 = new Point();
   Projection projection = (Projection) mapView.getProjection();
   projection.toPixels(start_, pt1);
   projection.toPixels(end_, pt2);
   Path mPath = new Path();
   mPath.moveTo(pt2.x,pt2.y);
   mPath.lineTo(pt1.x, pt1.y);
   drawBitmapAlongPath(mPath, bitmap, canvas);
}

void drawBitmapAlongPath(Path p, Bitmap b, Canvas c) {
     Matrix m = new Matrix();
     PathMeasure meas = new PathMeasure(p, false);
     final float length = meas.getLength();
     final float advance = b.getWidth();   
     float distance = 0;
     final int flags = PathMeasure.POSITION_MATRIX_FLAG |  
             PathMeasure.TANGENT_MATRIX_FLAG;

     while (distance < length) {
         meas.getMatrix(distance, m, flags);
         c.drawBitmap(b, m, null);
         distance += advance;
     }
}