Performance issues drawing PolyLines in Android Google Maps API v2

I have a few doubts about drawing a polylines on a MapFragment.

Should I draw them in separate layer like TileOverlay or GroundOverlay, is it possible at all? I want to achieve good performance, as good as possible. Now I have a map fragment where I receive using Volley library some data from external server and in AsyncTask I draw every polyline separately in loop. Should I use AsyncTask for this? Volley requests working asynchronous I suppose, but in callback which is invoking by success listener where I invoke drawing polylines this work in the same thread what the main activity so I put this to AsyncTask.

I have list of polylines data and method where in loop I draw every polyline on the map:

  mMap.clear();
            for (PolyLineDTO polyLineDTO : currentPolyLines) {
                polyLines.add(drawPolyline(polyLineDTO));
            }

Method drawPolyline(polyLineDTO) just invoking mMap.addPolyline(polylineOptions).

When I have about 500 polylines drawn on the map, it noticeably slows.

What do you think?

Answers


I think you may want to rethink your design choice.

If you add 500 lines to show them on a small screen like phone's, you won't see the map.

If most of them are outside of the screen, don't add them until user scrolls there. Just calculate each Polyline's LatLngBounds and only add them when it intersects with getProjection().getVisibleRegion().latLngBounds.

And don't use AsyncTasks when you use Volley. Calls to GoogleMap's and other API v2 objects function must be done on the UI thread.


Need Your Help

Rhadoop with Elasticsearch-hadoop

hadoop elasticsearch rhadoop

I am using hadoop with a database from ElasticSearch (no hdfs).

UITableview titleForHeaderInSection not displaying correctly

iphone objective-c cocoa-touch uitableview

I have some VERY simple code to return the title for a section header:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.