Android绘制路径路径绘制功能

时间:2010-09-05 16:39:10

标签: android map

  

可能重复:
  How to draw a path on a map using kml file?
  Android draw a path on a mapView from a large amount of longitude/latitude points

在我的Android应用程序中,我在“绘制”Overlay类中使用此方法在地图上绘制路线。

有人可以告诉我这个方法在地图上绘制路线是否合适(在性能方面)还是我必须将代码放在线程中?

我是初学者。

`

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

  if (pointsAndTimes.isEmpty()) {

   return;


  }
  Projection projection = mapView.getProjection();
  Paint paint = new Paint();
  paint.setARGB(250, 255, 0, 0);
  paint.setAntiAlias(true);
  paint.setFakeBoldText(true);
  paint.setStrokeWidth(4);
  paint.setAlpha(100);  



  for (int i = 0; i < pointsAndTimes.size(); i++) {
   PointAndTime pointAndTime = pointsAndTimes.get(i);
   Point point = projection.toPixels(pointAndTime.getGeoPoint(), null);

   if (i == pointsAndTimes.size() - 1) {

   } else {
    PointAndTime nextPointAndTime = pointsAndTimes.get(i + 1);

    Point nextPoint = projection.toPixels(nextPointAndTime
      .getGeoPoint(), null);
    canvas.drawLine(point.x, point.y, nextPoint.x, nextPoint.y,
      paint);
   }


  }
  mapView.invalidate();


 }`

由于

0 个答案:

没有答案