【发布时间】:2012-02-26 04:36:23
【问题描述】:
有没有人有关于如何使用带有逗号分隔的纬度经度坐标的 csv 文件在地图叠加层上绘制路线以用于爬山应用程序的教程或示例。 csv 文件将存储在 assets 文件夹中。
我是 android 开发的新手,一直在寻找高低,但至今没有成功。
非常感谢。
许多坦克的评论 - 我已经到了可以绘制路径但只能绘制其他点的地步,我的下一个问题是如何循环遍历 csv 文件以显示连续路径 - 代码如下。
class WalkOverlay extends Overlay{
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(5);
// start csv parser
try {
InputStream is = getAssets().open("CSV/Mountain Walks/llanberisPath.csv");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
while ((line = reader.readLine()) != null) {
String[] RowData = line.split(",");
longitude = RowData[0];
latitude = RowData[1];
Double lat = new Double(latitude);
Double lng = new Double(longitude);
geoPoint1 = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
gP1 = geoPoint1;
gP2 = geoPoint2;
p1 = new Point();
p2 = new Point();
path = new Path();
Projection projection = mapv.getProjection();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
}
}
catch (IOException ex) {
// handle exception
}
finally {
try {
is.close();
}
catch (IOException e) {
// handle exception
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
【问题讨论】:
标签: android