Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13007] Android: Maps V2 Module - Click Event Listeners not working on a map

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-03-29T22:20:07.000+0000
Affected Version/sRelease 2.1.3
Fix Version/sRelease 3.1.0, 2013 Sprint 07 API, 2013 Sprint 07
ComponentsAndroid
LabelsSupportTeam, mapv2, qe-testadded
ReporterEduardo Gomez
AssigneeHieu Pham
Created2013-03-08T17:08:30.000+0000
Updated2013-09-25T06:53:38.000+0000

Description

Expected results

A alert dialog should pop up and the info should be logged

Actual results

On DDMS but nothing happens.

Steps to reproduce

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;

Additional details

Public link 2.1.3.MapsModule patched 2.1.3.GA SDK for use: http://dl.dropbox.com/u/34061091/mobilesdk-2.1.3.MapsModule-osx.zip

Comments

  1. Ping Wang 2013-03-15

    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();
       
  2. Eduardo Gomez 2013-03-15

    Simple sample posted initially reproduces the following (clicking any annotation):
       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 6488161
       
    It may be just one of the features was not supported but reported already for Map V2 Module.
  3. Ping Wang 2013-03-15

    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?
  4. Eduardo Gomez 2013-03-15

    Thanks for clarifying, yes, it works. I should have updated to latest 3.1 SDK.
  5. Eduardo Gomez 2013-03-26

    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.3
  6. Ping Wang 2013-03-27

    PR to fix NPE: https://github.com/appcelerator/titanium_modules/pull/94
  7. Dhirendra Jha 2013-09-25

    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.

JSON Source