So I am extending an ItemizedOverlay, and using a rest query to make an async http request to web service where I can get the coordinates of lots of push pins.
Once the handler gets the async http request I do the following (maybe not the best solution – ie. clearing all records all the time). But I am open to suggestions (hence the post)..
Basically here is the code flow (I have a list view & map view on a flipper and want to keep them in sync – hence the arrayAdapter;
locationRecords.clear(); // ArrayList<LocationRecord>
updateScreen(jArray); // jSONArray jArray
arrayAdapter.notifyDataSetChanged();
updateOverlay();
private synchronized void updateOverlay() {
// Clear the previous overlay of map push pins (don't want to keep adding new overlays)
Iterator<Overlay> listofOverlays = mapView.getOverlays().iterator();
while (listofOverlays.hasNext()) {
Overlay tempOverlay = listofOverlays.next();
if (tempOverlay.getClass().equals(MunzeeOverlay.class)) {
mapView.getOverlays().remove(tempOverlay);
}
this.notify();
}
MyOverlay overlay = new MyOverlay(MapTools.getGreenMarker(mContext),mapView);
Iterator<LocationRecord> mapList = locationRecords.iterator();
while (mapList.hasNext()) {
overlay.addOverlay(mapList.next().getOverlayItem());
}
mapView.getOverlays().add(overlay);
}
protected void updateScreen(JSONArray jArray) {
if ( jArray != null ) {
for ( int i = 0; i < jArray.length(); i++ ) {
try {
JSONObject myArray = jArray.getJSONObject(i);
locationRecords.add(new LocationRecord(myArray,mContext));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
My thought is on the myOverlay that I can do a check when I addOverlay w/ an equiv check and make sure it is not already there, that way i would not need to delete the overlay on the map?
I also am seeing some ConcurrentModificationExceptions in updateOverlay (I suppose that could have to do w/ clearing the locationRecords & updatingScreen not in a synchronized manner.. Sooo..
1) Any suggestions for improving map pin performance, and not seeming to freeze the map while it is updating the overlay
2) Any suggestions on fixing the ConcurrentModificationExceptions?
Have one overlay with N pins. Near as I can tell, you have N overlays with one pin each. This is bad.
When your data arrives, call
populate()on the one-and-only overlay to have Android reload all of the markers — you do not need to clear anything yourself.