Removing annotations / iPhone simulator crash
I am currently creating annotations and am storing them in an array. At a later point I am creating new annotations and am removing old ones. The array is used to keep track of which annotations are currently placed on the map. Therefore I'd have to as well remove the annotation from my array once I am removing it from the map. Something like:
mapview.removeAnnotation(annotations[x]);
delete annotations[x];
Unfortunately this crashes the simulator, because — as far as I understand it — the mapview tries to remove the annotation after it has already been deleted from the array (iPhone OS specific?) and I'm getting the following error:
Terminating app due to uncaught exception 'org.appcelerator.TiMapView', reason: 'Invalid type passed to function. expected: NSDictionary, was: NSNull in -[TiMapView annotationFromArg:] (TiMapView.m:72)
What would be the appropriate way of doing this? Am somehow missing something?
Cheers!
3 Answers
-
remove the delete annotation[x] line.:
this is what i use for removing annotations
function removeAnnotations(){ for (var a=annotations.length-1;a>=0;a--) { mapview.removeAnnotation(annotations[a]); Ti.API.info("removing annotation"); } annotations = []; }
-
Thanks for your answer. My problem is, that I don't want to simply "empty" the whole array, but rather remove single members. That's why I can't use
annotations = [];
in this case. I don't really understand why delete causes this problem in this case. Any other ideas?
-
I'm currently having some problems myself with removeAnnotation()… I'm not sure I understand your problem completely, and not sure if it helps in this case, but to remove the annotation from your array try something like
annotations.splice(annotationIndex,1);