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; } }