在Android Google Map中绘制kml坐标

时间:2012-07-24 21:13:48

标签: android google-maps kml android-maps

我正在创建一个Android应用程序来映射我们当地的山地自行车道。坐标来自KML文件。到目前为止,我已经绘制并创建了11个GeoPoints的路径。但是,我有数百个坐标来映射。这是我迄今为止所做的代码。这是有效的,但它非常繁琐,我还有数百个要做。有没有更好的方法呢?有没有办法让我的叠加层读取我的kml文件中的坐标?任何其他想法或想法都表示赞赏。

public void draw(Canvas canvas, MapView mapView, boolean shadow) {
     super.draw(canvas, mapView, shadow);
     Paint paint;
     paint = new Paint();
     paint.setDither(true);
     paint.setColor(Color.RED);
     paint.setStyle(Paint.Style.FILL_AND_STROKE);
     paint.setStrokeJoin(Paint.Join.ROUND);
     paint.setStrokeWidth(2);

     GeoPoint gp1 = new GeoPoint(43311836,-91777756);
     GeoPoint gp2 = new GeoPoint(43311718,-91777699);
     GeoPoint gp3 = new GeoPoint(43311718,-91777699);
     GeoPoint gp4 = new GeoPoint(43311666,-91777627);
     GeoPoint gp5 = new GeoPoint(43311624,-91777541);
     GeoPoint gp6 = new GeoPoint(43311582,-91777455);
     GeoPoint gp7 = new GeoPoint(43311533,-91777369);
     GeoPoint gp8 = new GeoPoint(43311489,-91777249);
     GeoPoint gp9 = new GeoPoint(43311445,-91777136);
     GeoPoint gp10 = new GeoPoint(43311404,-91776996);
     GeoPoint gp11 = new GeoPoint(43311410,-91776891);
     Point pt1 = new Point();
     Point pt2 = new Point();
     Point pt3 = new Point();
     Point pt4 = new Point();
     Point pt5 = new Point();
     Point pt6 = new Point();
     Point pt7 = new Point();
     Point pt8 = new Point();
     Point pt9 = new Point();
     Point pt10 = new Point();
     Point pt11 = new Point();

     Path path1 = new Path();
     Path path2 = new Path();
     Path path3 = new Path();
     Path path4 = new Path();
     Path path5 = new Path();
     Path path6 = new Path();
     Path path7 = new Path();
     Path path8 = new Path();
     Path path9 = new Path();

     projection.toPixels(gp1,pt1);
     projection.toPixels(gp2, pt2);
     projection.toPixels(gp3, pt3);
     projection.toPixels(gp4, pt4);
     projection.toPixels(gp5, pt5);
     projection.toPixels(gp6, pt6);
     projection.toPixels(gp7, pt7);
     projection.toPixels(gp8, pt8);
     projection.toPixels(gp9, pt9);
     projection.toPixels(gp10, pt10);
     projection.toPixels(gp11, pt11);

     path1.moveTo(pt1.x, pt1.y);
     path1.lineTo(pt2.x, pt2.y);

     path2.moveTo(pt3.x,pt3.y);
     path2.lineTo(pt4.x, pt4.y);

     path3.moveTo(pt4.x,pt4.y);
     path3.lineTo(pt5.x,pt5.y);

     path4.moveTo(pt5.x, pt5.y);
     path4.lineTo(pt6.x, pt6.y);

     path5.moveTo(pt6.x, pt6.y);
     path5.lineTo(pt7.x, pt7.y);

     path6.moveTo(pt7.x, pt7.y);
     path6.lineTo(pt8.x, pt8.y);

     path7.moveTo(pt8.x, pt8.y);
     path7.lineTo(pt9.x, pt9.y);

     path8.moveTo(pt9.x,pt9.y);
     path8.lineTo(pt10.x, pt10.y);

     path9.moveTo(pt10.x, pt10.y);
     path9.lineTo(pt11.x, pt11.y);

     canvas.drawPath(path1, paint);
     canvas.drawPath(path2, paint);
     canvas.drawPath(path3, paint);
     canvas.drawPath(path4, paint);
     canvas.drawPath(path5, paint);
     canvas.drawPath(path6, paint);
     canvas.drawPath(path7, paint);
     canvas.drawPath(path8, paint);
     canvas.drawPath(path9, paint);

  }
}

1 个答案:

答案 0 :(得分:0)

你难道不能只读入KML文件并遍历这些点吗?