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:
var MapModule = require('ti.map'); var win = Ti.UI.createWindow({fullscreen: false}); var anno = MapModule.createAnnotation({latitude: -33.87365, image: 'KS_nav_ui.png', longitude: 151.20689, title: "Drag Me", subtitle: "Sydney is quite chill", draggable: true}); var anno2 = MapModule.createAnnotation({latitude: -33.86365, pincolor: MapModule.ANNOTATION_BLUE, longitude: 151.21689, title: "Drag Me 2", subtitle: "This is anno2", draggable: true}); var anno3 = MapModule.createAnnotation({latitude: -33.85365, longitude: 151.20689, title: "anno3", subtitle: "This is anno3", draggable: false}); var map = MapModule.createView({ userLocation: true, mapType: MapModule.NORMAL_TYPE, animate: true, annotations: [anno, anno2, anno3], region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 }, //Sydney top: '30%' }); map.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(); }); win.add(map); win.open();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.03-14 19:12:21.382: E/TiApplication(24613): (main) [1061,5786] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 2.1.3.MapsModule,2013/03/04 08:32,15997d0 03-14 19:12:21.382: E/TiApplication(24613): java.lang.NullPointerException 03-14 19:12:21.382: E/TiApplication(24613): at ti.map.TiUIMapView.onMarkerClick(TiUIMapView.java:369) 03-14 19:12:21.382: E/TiApplication(24613): at com.google.android.gms.maps.GoogleMap$4.f(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at com.google.android.gms.internal.an$a.onTransact(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at android.os.Binder.transact(Binder.java:295) 03-14 19:12:21.382: E/TiApplication(24613): at com.google.android.gms.maps.internal.IOnMarkerClickListener$Stub$Proxy.onMarkerClick(IOnMarkerClickListener.java:84) 03-14 19:12:21.382: E/TiApplication(24613): at maps.z.by.a(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.y.ba.a(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.y.d.c(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.y.bj.a(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.y.v.c(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.y.bf.onSingleTapConfirmed(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.d.v.onSingleTapConfirmed(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at maps.d.j.handleMessage(Unknown Source) 03-14 19:12:21.382: E/TiApplication(24613): at android.os.Handler.dispatchMessage(Handler.java:99) 03-14 19:12:21.382: E/TiApplication(24613): at android.os.Looper.loop(Looper.java:130) 03-14 19:12:21.382: E/TiApplication(24613): at android.app.ActivityThread.main(ActivityThread.java:3859) 03-14 19:12:21.382: E/TiApplication(24613): at java.lang.reflect.Method.invokeNative(Native Method) 03-14 19:12:21.382: E/TiApplication(24613): at java.lang.reflect.Method.invoke(Method.java:507) 03-14 19:12:21.382: E/TiApplication(24613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840) 03-14 19:12:21.382: E/TiApplication(24613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598) 03-14 19:12:21.382: E/TiApplication(24613): at dalvik.system.NativeStart.main(Native Method) 03-14 19:12:21.421: E/AndroidRuntime(24613): FATAL EXCEPTION: main 03-14 19:12:21.421: E/AndroidRuntime(24613): java.lang.NullPointerException 03-14 19:12:21.421: E/AndroidRuntime(24613): at ti.map.TiUIMapView.onMarkerClick(TiUIMapView.java:369) 03-14 19:12:21.421: E/AndroidRuntime(24613): at com.google.android.gms.maps.GoogleMap$4.f(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at com.google.android.gms.internal.an$a.onTransact(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at android.os.Binder.transact(Binder.java:295) 03-14 19:12:21.421: E/AndroidRuntime(24613): at com.google.android.gms.maps.internal.IOnMarkerClickListener$Stub$Proxy.onMarkerClick(IOnMarkerClickListener.java:84) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.z.by.a(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.y.ba.a(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.y.d.c(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.y.bj.a(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.y.v.c(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.y.bf.onSingleTapConfirmed(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.d.v.onSingleTapConfirmed(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at maps.d.j.handleMessage(Unknown Source) 03-14 19:12:21.421: E/AndroidRuntime(24613): at android.os.Handler.dispatchMessage(Handler.java:99) 03-14 19:12:21.421: E/AndroidRuntime(24613): at android.os.Looper.loop(Looper.java:130) 03-14 19:12:21.421: E/AndroidRuntime(24613): at android.app.ActivityThread.main(ActivityThread.java:3859) 03-14 19:12:21.421: E/AndroidRuntime(24613): at java.lang.reflect.Method.invokeNative(Native Method) 03-14 19:12:21.421: E/AndroidRuntime(24613): at java.lang.reflect.Method.invoke(Method.java:507) 03-14 19:12:21.421: E/AndroidRuntime(24613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840) 03-14 19:12:21.421: E/AndroidRuntime(24613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598) 03-14 19:12:21.421: E/AndroidRuntime(24613): at dalvik.system.NativeStart.main(Native Method) 03-14 19:12:21.429: W/ActivityManager(499): Force finishing activity com.map/.MaptestActivity 03-14 19:12:21.476: W/ApplicationContext(499): Unable to create files directory 03-14 19:12:21.500: I/gralloc(499): Allocated 0x20797469 size 1937072496 03-14 19:12:21.929: W/ActivityManager(499): Activity pause timeout for HistoryRecord{40bea4e0 com.map/.MaptestActivity} 03-14 19:12:21.968: D/ActivitityRenderTarget(875): onResume 03-14 19:12:21.984: W/IMGSRV(875): eglglue.c:778: InitContext: ignoring buffer type CBUF_TYPE_PDS_VERT_SECONDARY_PREGEN_BUFFER 03-14 19:12:21.992: I/gralloc(499): Allocated 0x660072 size 6488161 03-14 19:12:22.140: I/gralloc(499): Allocated 0x660072 size 6488161 03-14 19:12:22.195: I/gralloc(499): Allocated 0x660072 size 6488161 03-14 19:12:22.265: I/gralloc(499): Allocated 0x660072 size 6488161Eduardo, 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.