The problem with a large number of markers on the map

I am working on an Android application that already exists on the iPhone.

There is a map activity in the application, in which (I calculated) about 800 markers in four groups, marked by highlighting in four different colors. Each group can be turned on or off. Information about the markers that I have inside the list. I create mapOverlay for each group, then I attach this overlay to the map. I strongly believe that I did the part of the coding correctly. But I still attach my code ...

The fact is that my Nexus One cannot process a card with all of these markers. It takes about 15 seconds to draw 500 markers. Then, when everything is drawn, the map is not quite smooth. It is difficult to scale and move. This can be done, but the experience is bad, and I would like to see what can be done there. I know that if I avoid String> Double conversion, I could save some time, but I doubt it would be significant.

The iPhone seems to have no problem displaying all of these markers. It takes about 1-2 seconds to show everything, and zooming and panning is not so bad. The slowdown is noticeable, but still acceptable. I personally think that it’s not good to draw all these markers, but the application was developed by someone else, and I should not make any major changes.

I'm not sure what to do here. It seems that I will have to come up with different functionality, perhaps use a GPS location, if known, and draw only markers within a radius, or if the location is unknown, use the center of the screen (map) and draw markers around it. I will have a reasonable explanation for my bosses if these changes are made.

I appreciate if anyone has an ida.

And the code:

List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.pin_blue); drawable = this.getResources().getDrawable(R.drawable.pin_blue); ArrList = appState.GetSleepArrList(); ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, this); ... ... for (int m = 0; m < ArrList.size(); m++) { tName = ArrList.get(m).get("name").toString(); tId = ArrList.get(m).get("id").toString(); tLat = ArrList.get(m).get("lat").toString();; tLng = ArrList.get(m).get("lng").toString();; try { lat = Double.parseDouble(tLat); lng = Double.parseDouble(tLng); p1 = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); OverlayItem overlayitem = new OverlayItem(p1, tName, tId); itemizedoverlay.addOverlay(overlayitem); } catch (NumberFormatException e) { Log.d(TAG, "NumberFormatException" + e); } } mapOverlays.add(itemizedoverlay); mapView.postInvalidate(); 

................................

 public class ItemizedOverlay extends ItemizedOverlay<OverlayItem> { private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); private Context mContext; public HelloItemizedOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context; } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } @Override protected OverlayItem createItem(int i) { return mOverlays.get(i); } @Override public int size() { return mOverlays.size(); } @Override protected boolean onTap(int index) { final OverlayItem item = mOverlays.get(index); ... EACH MARKER WILL HAVE ONCLICK EVENT THAT WILL PRODUCE CLICABLE ... BALOON WITH MARKER NAME. return true; } } 
+6
android map
source share
3 answers

Well. It turned out that I call populate () every time after adding a marker. I took populate () from the addOverlay () method, and I call it after the loop finishes. All markers now show almost instantly. The only problem now is that the card really doesn’t respond when at a lower zoom (showing many markers at once). I don’t see a solution for this, if I don’t figure out how to reduce the number of markers on the map when the map is reduced ... thinking to group them somehow ... currently working on it ...

+3
source share

There are two ways to simplify this route.

1) If you received the title of all points. You can keep the course tolerance, say, if the difference in course between point A and B is 0.5 Just draw a line from A to B and ignore the points between them.

2) If you do not have a headline. Make a triangle as shown in fig. If h lies between your limits, skip the points between them and draw a line from A to B enter image description here

You can also use some other route simplification algorithms .


See also:

Route Simplification - Douglas Pucker Algorithm

+2
source share

I have the same problem when loading multiple markers onto the map, but I put some delay in loading the marker and displaying the map. At first the map will be displayed and after some delay it will load the entire marker. which will load faster to some extent.

0
source share

All Articles