0

I am new to Titanium and in the process of making my first iOS app using Titanium but I've hit a wall with a use case.

I am trying to open an annotation on the map by clicking on a particular row on a table view. I haven't had much success with this and was unable to find any help online. Is this impossible to do or am I just doing something wrong? The following is my code:

table.addEventListener('click', function (event) {
    Ti.API.info("Index of row that is clicked: "+event.index);
    globals.annos[event.index].fireEvent('click');
});

'table' is my TableView with a bunch of rows and global.annos[] is my array of annotations.

My objective is to open the annotation corresponding to the index of the table row that I have clicked. The above code doesn't achieve anything. I thought firing the 'click' event of the annotation would open the annotation but clearly I was mistaken.

Could someone help me out here? Any help would be much appreciated.

ares05
  • 177
  • 4
  • 9

2 Answers2

0

If you are using Android the click event for annotations is not supported. A more cross platform approach is to fire the click event on the MapView itself.

But if you are using iOS, your click event is not set correctly, you have to define what part of the annotation your clicking, according to the documentation :

On iOS, if the user clicks on the pin or annotation, the clicksource is one of: pin, annotation, leftButton, rightButton, leftView, rightView, title, or subtitle. If the user deselects the annotation by clicking elsewhere in the map view, clicksource is null.

And you didnt pass an event object that defines the properties of the synthesized event. Try this inside your table event listener:

var event = {
    source : table,
    type : 'click',
    clicksource : 'pin'
};
globals.annos[event.index].fireEvent('click', event);
Josiah Hester
  • 6,065
  • 1
  • 24
  • 37
0

SOLVED! Lack of reading the docs more thoroughly!

mapview.selectAnnotation(globals.annos[event.index]);

This opens the corresponding annotation.

ares05
  • 177
  • 4
  • 9