Titanium Community Questions & Answer Archive

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

Annotation labels cause regionChanged Event to fire?

I have a MapView with annotations from a database. This MapView uses the "regionChanged" event to determine when to update annotations (removeAll and then add all). The problem is that this event seems to fire to often. Selecting a pin sometimes requires the map to move to make space for the label, thus causing "regionChanged" to fire.

Have you dealt with this? How did you get around this? Perhaps I need to get a little more creative with when/how I load my annotations from the database.

— asked September 12th 2010 by Bart Lewis
  • database

2 Answers

  • I spent hours try to figure out how to work around this. In the end it was the simple answer that worked the best.

    Add a variable that is visible to the entire section of code used for the MapView.

    var preventRefresh = false;

    Then in your code add an event listener for the MapView click event and set the variable to true if the clicksource was 'pin'.

        var clickSource = evt.clicksource;
        if(evt.clicksource == 'pin'){
            preventRefresh = true;

    Then in your code for the regionChanged event listener check to make sure the variable is 'false' before firing the code to for the regionChanged event. (I have a function to update my annotations).

    mapview.addEventListener('regionChanged', function(e){
        if(preventRefresh == false){
            preventRefresh = false;

    Don't forget to set the else to reset your variable to false.

    Now the regionChanged code is ignored when the pin is clicked causing the bubble above it to make the MapView move.

    I hope this prevents male-pattern-baldness in someone else. For me, it's too late.

    — answered June 7th 2011 by Kenneth Lewis
  • For those that may run into this thread with the same issue: I did end up getting more creative with how I load my annotations.

    I have some logic that loops through annotations, deletes annotations that are now off screen, adds new annotations, and leaves annotations that are still on the screen alone.

    — answered September 20th 2010 by Bart Lewis
    • Would you care to share your code/logic behind doing this?

      — commented January 13th 2011 by Ian Tearle
    • Hi Kenneth, could you share your logic code?, struggling with this issue

      — commented January 24th 2012 by karl andreasson
    • Hi, do you mind sharing some code.. Much appreciated

      — commented July 21st 2012 by Hasnaad Din
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.