Override Overlay draw method.

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Override Overlay draw method.

Postby radioblaster » Thu Aug 06, 2009 11:22 pm

Trying to figure out how to draw a path on a MapView and all the examples I have seen extend Overlay and override the draw method. I tried this but because draw appears to be called over and over again (i assume every screen refresh so probably thousands of times per second...). This causes the UI to *almost* lock up (run really really slow) because the app is constantly using 100% of the CPU trying to call the draw method over and over.

Anyone know how to draw a path/trail/track overlay without overriding the draw method, or how to optimize it so draw isn't called continually?

Thanks!
radioblaster
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jul 16, 2009 4:29 pm

Top

Postby radioblaster » Fri Aug 07, 2009 5:51 pm

Well, I changed my logic a bit so that I no longer querying a db for points within the draw method. The query is done during the constructor so that all the GeoPoints are in a List in memory every time draw is called. Performance is better now.
radioblaster
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jul 16, 2009 4:29 pm

Postby dma » Wed Sep 30, 2009 8:41 am

Hi all,

I'm issuing very same problem. Even if the code looks like:

@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
return true;
}

it's still using 100% of CPU time cause it always calls draw() method over and over (like in a loop). If user stays on this screen and leave the phone for awhile the battery will be drained soon.

Please, did someone have this problem before or is there any workaround or maybe tip for this?

Thanks
dma
Freshman
Freshman
 
Posts: 2
Joined: Wed Sep 30, 2009 8:21 am

Postby dma » Wed Sep 30, 2009 12:29 pm

Here's the solution: false value should be returned instead of true value. This should fix high CPU usage.

Best regards.
dma
Freshman
Freshman
 
Posts: 2
Joined: Wed Sep 30, 2009 8:21 am

Postby gazzaaa87 » Wed Mar 03, 2010 12:23 pm

This didn't fix the problem for me.

I was previously overriding the void draw(Canvas, MapView, boolean) method and have now switched to the other draw method. I return false without calling the super method and it is still called continuously. Am I doind something wrong:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. @Override
  3.  
  4. public boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
  5.  
  6. {
  7.  
  8. drawMapLocations(canvas, mapView, shadow);
  9.  
  10.                 drawInfoWindow(canvas, mapView);
  11.  
  12.                
  13.  
  14.                 return false;
  15.  
  16.         }
  17.  
  18.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
gazzaaa87
Freshman
Freshman
 
Posts: 4
Joined: Wed Mar 03, 2010 11:16 am

Re: Override Overlay draw method.

Postby singalen » Tue May 25, 2010 1:11 pm

Get back to overriding the method without "when" parameter.
The other one is intended for animated overlay, so it will be polled all the time.
singalen
Once Poster
Once Poster
 
Posts: 1
Joined: Tue May 25, 2010 1:08 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests