Please add an Click Event Listener for Map or use sample below on project under test (attached on Timob-13004 as well).
//FirstView Component Constructor
function FirstView() {
var self = Ti.UI.createView();
var MapModule = require('ti.map');
var map1 = MapModule.createView({
userLocation: true,
mapType: MapModule.NORMAL_TYPE,
animate: true,
region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 }, //Sydney
height: '80%',
top: 0,
left: 0,
width: '100%'
});
var anno1 = MapModule.createAnnotation({
latitude: -33.86665,
longitude: 151.20689,
title: "Anno2",
subtitle: "Ann2 subtitle",
animate: true,
id: 33
});
anno1.image = '/mbanking/images/Locations-Pin-Android-red-hdpi.png';
anno1.rightButton = '/images/locations-android-popover-arrow.png';
anno1.rightButton.height = 44;
anno1.rightButton.width = 46;
var anno2 = MapModule.createAnnotation({
latitude: -33.87365,
longitude: 151.20689,
title: "Anno2",
subtitle: "Ann2 subtitle",
animate: true,
id: 43
});
anno2.image = '/mbanking/images/Locations-Pin-Android-red-hdpi.png';
anno2.rightButton = '/images/locations-android-popover-arrow.png';
anno2.rightButton.height = 44;
anno2.rightButton.width = 46;
var anno3 = MapModule.createAnnotation({
latitude: -33.87964,
longitude: 151.21130,
title: "Anno3",
subtitle: "Ann3 subtitle",
animate: true,
id: 45
});
anno3.image = '/mbanking/images/Locations-Pin-Android-red-hdpi.png';
anno3.rightButton = '/images/locations-android-popover-arrow.png';
anno3.rightButton.height = 44;
anno3.rightButton.width = 46;
var anns = [];
anns.push(anno1);
anns.push(anno2);
anns.push(anno3);
map1.addAnnotations(anns);
setTimeout(function () {
map1.selectAnnotation(anno1, true);
map1.setHeight('100%');
}, 8000);
map1.addEventListener('click', function(e) {
var alert = Ti.UI.createAlertDialog({
title: 'Clicked!',
message: 'e.annotation.id: ' + e.annotation.id + "e.annotation.index: " + e.annotation.index
});
Ti.API.info("Annotation " + e.title);
alert.show();
});
self.add(map1);
return self;
}
module.exports = FirstView;
Cannot reproduce with the latest Maps V2 Module. The "click" event works fine. *Note:* Based on the [doc](http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.View-event-click), the click event is not fired every time the user clicks on the map. It is fired in two circumstances: 1. If the user clicks on an annotation to select it. 2. The user deselects an annotation. BTW, based on the doc, Annotation does not support the "id" or "index" property. Here is a simple test case:
Simple sample posted initially reproduces the following (clicking any annotation):
It may be just one of the features was not supported but reported already for Map V2 Module.
Eduardo, the log you posted is a NPE which seems a bug in the module. I ran the original test case you posted with latest 3.1.0 SDK but it still works fine. Alert shows without any crash. Can you try it on 3.1.0 SDK to see if it works?
Thanks for clarifying, yes, it works. I should have updated to latest 3.1 SDK.
I can confirm that the click event works if you do not add the annotation via the addAnnotations method. If I add it while creating the map then the click event is fired.
Tested on
Droid Razr 2.3.5 & patched SDK 2.1.3PR to fix NPE: https://github.com/appcelerator/titanium_modules/pull/94
Environment - Appcelerator Studio: 3.1.3.201309132456 SDK: 3.1.3.GA acs: 1.0.6 alloy: 1.2.2 npm: 1.3.2 titanium: 3.1.2 titanium-code-processor: 1.0.3 Device: Nexus 7 (v4.3) Result - Click event is fired on select/deselect the annotation. Also did not observe crash on clicking annotation. Hence closing this issue.