does anyone have a tutorial or example of how to use a csv file with comma separated latitude longitude coordinates to draw a route on a map overlay for use in a hill walking application. The csv file is to be stored in the assets folder.
I am new to android development and have been searching high and low with no success to date.
Many thanks in advance.
Many tanks for the comment - I have got to the point where I can draw a path but only every other point, my next question is how do you loop through the csv file to show a continuous path - code below.
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();
}
}
}