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.


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."




// This one doesnt work.

// Neither does this ("Oslo" is the title of an annotation.)

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.


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

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 );
    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
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.