tags:

views:

59

answers:

1

Hi,

In my android application I use this method in "draw" Overlay class for draw route on map.

Can someone tell me if this method is good (in terms of performance) for route draw on map or I must to put code in Thread ??

I'm new to android.

`

public synchronized void draw(Canvas canvas, MapView mapView, boolean shadow) {

if (pointsAndTimes.isEmpty()) {

return;

} Projection projection = mapView.getProjection(); Paint paint = new Paint(); paint.setARGB(250, 255, 0, 0); paint.setAntiAlias(true); paint.setFakeBoldText(true); paint.setStrokeWidth(4); paint.setAlpha(100);

for (int i = 0; i < pointsAndTimes.size(); i++) { PointAndTime pointAndTime = pointsAndTimes.get(i); Point point = projection.toPixels(pointAndTime.getGeoPoint(), null);

if (i == pointsAndTimes.size() - 1) {

} else { PointAndTime nextPointAndTime = pointsAndTimes.get(i + 1);

Point nextPoint = projection.toPixels(nextPointAndTime
  .getGeoPoint(), null);
canvas.drawLine(point.x, point.y, nextPoint.x, nextPoint.y,
  paint);

}

} mapView.invalidate();

}`

Thanks

A: 

Here's a code sample:

http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723

Mathias Lin
In my case I get GeoPoints on different way (not from KML file). Can you please tell me where drawPath method is called? Where to call this method? Thanks
Jovan
look at the last two code pieces starting with the "Drawing:" headline, that's the relevant part. Doesn't matter if data comes from KML or elsewhere. You can call the method from anywhere in you code, i.e. same position as you do with your above code sample, in the onCreate of your activity for example. http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723
Mathias Lin