2012-04-17 2 views
4

다음은지도에서 지오 포인트 사이의 경로를 그리는 코드입니다. 이것은 완벽하게 작동합니다. 내가 구현하려고하는 것은 선을 그리는 대신 iPhone에서와 같이 점 (.)으로이 경로를 표시하는 것입니다. gp1_ _ __ _ _gp2와 같이 한 줄로 그리는 대신 gp1이 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); 
} 

}이 사람에

+1

http://stackoverflow.com/questions/6167236/canvas-drawlines-disjointed-segments – MKJParekh

+0

이 퀘스트인가요? 이온은 이전 구글지도 api를 사용하여 (이 코멘트를 쓰는 순간, 현재 하나는 v2입니다)? – DNax

답변

10

덕분에, 나는이 예제를 언급하고 나를 위해 노력하고 있습니다.

How do I make a dotted/dashed line in Android?

그냥 감사, 내가 설정 한 후

paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 5)); 
    canvas.drawLine(point.x, point.y, point2.x, point2.y, paint); 

,

paint.setAlpha(120); 

@Frankenstein,이 2 개 개의 라인을 추가 할 필요가

+0

당신도 환영합니다 :) – MKJParekh

+1

당신은 또한 자신의 대답을 받아 들일 수 있습니다 :) 또한 필요하다면 당신의 코드를 넣어 ... 건배 – MKJParekh

+1

@Frankenstein, 나는 2 일 후에 내 자신의 대답을 수락 할 수 있습니다 :(안 코드에 많은 변화를 주었고 fgPaintSel.setStyle (Style.STROKE);fgPaintSel.setPathEffect (새 DashPathEffect (새 float [] {10,20}, 0)); 페인트 – tejas