Titanium Community Questions & Answer Archive

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

Map click event fired only when clicking on annotation tooltip

Here is the code i have:

mapview.addEventListener('click',function(evt)
{
    var annotation = evt.annotation;
    var title = evt.title;
    alert(title);
});

The event fires only when clicking the annotation , and then clicking the tooltip. Idea how to fire the event when clicking only the annotation?

— asked September 28th 2010 by Filip Dimitrovski
  • android
  • annotation
  • event
  • map
  • mobile
0 Comments

8 Answers

  • newAnnotation.addEventListener('click',function(e) {
    });
    

    That one doesn't work , too :(

    — answered October 1st 2010 by Filip Dimitrovski
    permalink
    1 Comment
    • Filip - this is a comment not an answer. You should add a comment to your original question if you have more information to add, or respond to an an answer you receive by adding a comment under it.

      — commented November 8th 2010 by Paul Dowsett
  • Check evt.clicksource, it should tell you why the event fired.

    — answered September 28th 2010 by John McKnight
    permalink
    1 Comment
    • Event doesn't fire when clicking annotation in Android… That's my prob

      — commented September 28th 2010 by Filip Dimitrovski
  • First off it pays to be polite when you ask a question. I don't even need to help you but I was trying. Secondly a BUMP only irritates people. Maybe nobody else replied because you…

    1. Didn't give enough info about your problem.
    2. Clearly didn't even attempt to try what I suggested.

    BTW - If you had looked at evt.clicksource you will see it return things like 'pin' or 'rightButton' The reason is the event will be fired any time the annotation is clicked in ANY way. It's up to you to decide if it happened for the reason you want. If you just want to know that somebody clicked on the annotation you say something like this.

     if (evt.clicksource == 'pin') {
       // The annotation was clicked
     }
    
     if (evt.clicksource == 'rightButton') {
       // The callout accessory was clicked
     }
    
    — answered September 29th 2010 by John McKnight
    permalink
    1 Comment
    • 1.Sorry , i needed to BUMP because i am making app for a contest.
      2.The info is clear , event fires ONLY when i click on the title of the annotation.
      3.I've tried it. Doesn't work.

      — commented September 30th 2010 by Filip Dimitrovski
  • I have no idea if this info helps but if you set an image in an annotation you get a click as soon as you click on the image. The image could be a picture of a pushpin if you are trying to keep that look.

    — answered September 30th 2010 by John McKnight
    permalink
    7 Comments
    • Great idea… How can i add image into the annotation :( ?

      — commented September 30th 2010 by Filip Dimitrovski
    • Go here.

      http://stackoverflow.com/questions/1185611/mkpinannotationview-are-there-more-than-three-colors-available/2066487#2066487

      Choose a pushpin and save it to your Resources folder and call it pushpin.png (for example) and then in your annotation do something like this.

            friendAnnotation = Ti.Map.createAnnotation({
              latitude: lat,
              longitude: lng,
              title: title,
              subtitle: subtitle,
              image: 'pushpin.png',
              animate:true,
              myid: id
            });
      

      Basically all you do is just create another property in the annotation called image and point it to the image you are trying to load.

      — commented September 30th 2010 by John McKnight
    • Hmm , i am using "pinImage" because that is for Android… image is for iPhone i think :)

      — commented September 30th 2010 by Filip Dimitrovski
    • I've tried it. Doesn't work :( :(

      — commented September 30th 2010 by Filip Dimitrovski
    • Are you sure it should be pinimage on Android?

      — commented September 30th 2010 by John McKnight
    • I've tried image , it works but event always fires only when clicking annotation title.

      — commented September 30th 2010 by Filip Dimitrovski
    • We may be seeing differences between iPhone and Android event handling.

      You can also tie your click to each annotation instead of just putting one handler on the mapview. Have you tried doing something like this when you create the annotation?

      newAnnotation.addEventListener('click',function(e) {
      });
      

      — commented September 30th 2010 by John McKnight
  • And i am using ANDROID platform…

    — answered September 30th 2010 by Filip Dimitrovski
    permalink
    0 Comments
  • 1.Sorry , i needed to BUMP because i am making app for a contest. 2.The info is clear , event fires ONLY when i click on the title of the annotation. 3.I've tried it. Doesn't work

    — answered September 30th 2010 by Filip Dimitrovski
    permalink
    0 Comments
  • BUMP

    — answered September 29th 2010 by Filip Dimitrovski
    permalink
    0 Comments
  • BUMP!!!

    — answered September 29th 2010 by Filip Dimitrovski
    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.