I am using a MapActivity
. I take a set of GeoPoints from a webserver using JSON and parse it to decoded the Polyline code into geo-points (latitude and longitude) which are then stored in ArrayList<Geopoints>
.
These points then get drawn on the MapActivity
.
My problem is that it's not running efficiently since my ArrayList<Geopoints>
size is more than 2000. How can I increase the efficiency?
Sample code what i ve done while drawing is
ArrayList'<'Geopoints> mGeoPoints;
Say size of mGeoPoints=2000;
In a class extended by Overlay. some methods of that class how i am writing is.
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,long when) {
super.draw(canvas, mapView, shadow, when);
drawPath(mapView, canvas);
return true;
}
public void drawPath(MapView mv, Canvas canvas) {
int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
for (int i = 0; i < mGeoPoints.size(); i++) {
Point point = new Point();
mv.getProjection().toPixels(mGeoPoints.get(i), point);
x2 = point.x;
y2 = point.y;
if (i > 0) {
canvas.drawLine(x1, y1, x2, y2, paint);
}
x1 = x2;
y1 = y2;
}
}
This code is working fine. its drawing correctly on the map. When i zoom the map or move the map application is hanging.
I have set the zoom level to 16 mapController.setZoom(16);
; can any one help me? To make it run fast even when user zoom it by hand.