Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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:

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?


— asked April 7th 2010 by Florian Plank
  • annotation
  • array
  • crash
  • iphone
  • mapview
  • null
  • remove

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--) {
            Ti.API.info("removing annotation");
        annotations = [];
    — answered April 7th 2010 by Glenn Tillemans
  • 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?

    — answered April 7th 2010 by Florian Plank
  • 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

    — answered June 10th 2011 by Zhenya Kogan
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.