Hi i'm trying to draw an overlay onto a google map but i sometimes get an
ANR "Reason: keyDispatchingTimedOut ".
Can any one tell me what the best structure is to do the drawing and prevent
this?
My code is below. Thanks in advance for any help
public class MyMap extends MapActivity {
/** Called when the activity is first created. */
DBHelper dbhelp;
final String TAG = "SignalSpot";
String [][]rows;
MapView mapView;
Paint mPaint;
Handler serviceHandler;
RunTask rt;
MyLocationOverlay myLocationOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
dbhelp = new DBHelper(this);
refreshHeatmapData();
//TODO periodically refresh heatmap
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
serviceHandler = new Handler();
rt = new RunTask();
serviceHandler.postDelayed(rt ,5*1000);
myLocationOverlay.enableMyLocation();
mapView.getOverlays().add(new MyOverlay());
}
@Override
public void onDestroy()
{
super.onDestroy();
myLocationOverlay.disableMyLocation();
serviceHandler.removeCallbacks(rt);
}
public void refreshHeatmapData()
{rows = dbhelp.getAllRows(-1);}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class MyOverlay extends Overlay{
public MyOverlay(){}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
Projection p = mapv.getProjection();
Log.i(TAG,"MAP NO OF ROWS: "+rows.length);
for(int i=0;i<rows.length;i++)
{ Log.i(TAG,"ACtual Data to draw: "+rows[i][2]+", "+rows[i][3]);
int x = (int)(Double.parseDouble(rows[i][2])*1E6);
int y = (int)(Double.parseDouble(rows[i][3])*1E6);
Log.i(TAG,"Drawing point No:"+i+" @ "+x+","+y);
GeoPoint in = new GeoPoint(x,y);
Log.i(TAG,"GEO POINT- lat: "+in.getLatitudeE6()+", lon:
"+in.getLongitudeE6());
Point pixels = p.toPixels(in,null);
double ss = Double.parseDouble(rows[i][4]);
//test code for constant circle when zooming
float radius = p.metersToEquatorPixels(100);
RadialGradient g = new RadialGradient(pixels.x, pixels.y,
radius,getColor2(ss) , null,TileMode.CLAMP);
Paint gp = new Paint();
gp.setShader(g);
//myCanvas.drawCircle(x, y, radius, gp);
canvas.drawCircle(pixels.x, pixels.y, radius, gp);
}
}
}
class RunTask implements Runnable
{
public void run()
{ Log.i(TAG,"Map data refresh run task");
refreshHeatmapData();
serviceHandler.postDelayed( this, 5*1000 );
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en