Titanium Community Questions & Answer Archive

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

selectAnnotation after loop.

Hello!

I ran into an issue with the selectAnnotation today.
Im getting my records from an xml, looping through it and using mapview.addAnnotation(xmlMarker), like so:

var interval = setInterval(function()
{
  var dbMarker = Titanium.Map.createAnnotation({
    "data from xml here... title/long/lat etc."
  });

  mapview.addAnnotation(dbMarker);

  val++;

},100);

// This one doesnt work.
mapview.selectAnnotation(mapview.annotations[15],true);

// Neither does this ("Oslo" is the title of an annotation.)
mapview.selectAnnotation('Oslo',true);

The annotations adds just fine, but the selectAnnotation doesnt. Nothing happens after the points are added.

Before this code im not adding any annotations, just initializing the mapview and adding an eventlistener to it. The win.add(mapview); is done before the above code (if relevant). Im hoping to get some help on this, as this thing is one of the last pieces of my application.

Cheers,
Chris

— asked September 6th 2010 by Chris Magnussen
  • map
  • selectannotation
0 Comments

1 Answer

  • Accepted Answer

    I think you need to expose the markers somehow, because right now they are not.

    In the loop you are creating with setInterval, add the marker to a general scope defined array.

    var annt = [];
    
    
    setInterval( ....
    
    var dbMarker=...
    
    annt.push( dbMarker );
    
    ....},100)
    map.selectAnnotation( annt[15]) // this should work now
    

    The selection by name( 'Oslo') won't work, you need to pass the object to the function.
    The selection by mapview.annotations[15] wont work either because you did not passed an array with markers when constructing the map, but you are adding after.

    Let me know if it works :)

    — answered September 7th 2010 by Dan Tamas
    permalink
    0 Comments
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.