Drawing to MapView Incredibly Slow

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

Drawing to MapView Incredibly Slow

Postby aspekt9 » Wed Feb 10, 2010 6:38 am

In my app I am drawing bus routes on top of a MapView using Overlay. The routes have
anywhere between a dozen and a few hundred GPS coordinates that
describe the route that the bus takes.

The problem I'm having is that once I draw out all these lines using
drawLines panning/zooming the MapView is incredibly slow (even
clicking the 'Back' button takes a minute to happen).

I'm not sure how relevant it is, but I put in some debug code then
checked the logcat output and the MapView is repeatedly calling the
draw() method of the Overlay whether anything has changed or not. This
is happening several times a second and is causing a massive amount of
garbage collection to happen (2-3 MB every second).

Does anyone have any ideas/suggestions for a method to try and speed
this up?
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Top

Postby azraeal » Wed Feb 10, 2010 7:48 am

Do you have an invalidate() statement inside of the onDraw()? This causes constant redrawings as you've described.

If it's only several times a second (and not several hundred) you might also want to check if you have an postInvalidate() in one of your worker threads. Invalidate should only be called when you need to redraw.

Also, make sure you're not doing any hard computing on the UI thread. How do you know if it's on the UI thread? Anything you didn't explicitly put into another thread is on the UI thread. How you managed to not trigger the "App is not responding" message is beyond me.

Hope this helps.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby aspekt9 » Wed Feb 10, 2010 9:39 am

How would I draw just what the user is looking at on the screen? That way nothing outside the bounds of their view is drawn until they pan over to a different section?
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests