地元のマウンテン バイク トレイルをマッピングする Android アプリを作成しています。座標は KML ファイルからのものです。ここまでで、11 のジオポイントのパスをプロットして作成しました。ただし、マップする座標が何百もあります。これまでに行ったことのコードを次に示します。これは機能しますが、非常に面倒で、さらに何百ものやらなければならないことがあります。これを行うより良い方法はありますか?オーバーレイ クラスに 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);
}
}