Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7272] Android: change map annotation to fire event when the annotation pin is clicked

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-01-18T18:34:25.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sSprint 2012-02, Release 2.0.0, Release 1.8.1
ComponentsAndroid
Labelsmodule_map, parity, qe-testadded
ReporterOpie Cyrus
AssigneeOpie Cyrus
Created2012-01-18T07:56:22.000+0000
Updated2012-03-02T14:57:59.000+0000

Description

In Android, when click on a annotation pin within the map view the description box is presented but not click event is fired. A user must click the description box that is displayed in order to fire a event back to javascript. A click event should be fired in both cases.

Comments

  1. Opie Cyrus 2012-01-18

    Test app.js
       /*var win = Ti.UI.createWindow({fullscreen:true,navBarHidden:true,width:320,height:480,orientationModes:[Titanium.UI.PORTRAIT]});
       var foo = Ti.UI.createButton({width:200,height:40,title:'LAUNCH',color:'black'})
       win.add(foo);
       	
       foo.addEventListener('click',function(){
       	var win1 = Titanium.UI.createWindow({url:"map.js"});
       	win1.open();
       });
       	
       win.open();
       */
       
       var win = Titanium.UI.createWindow();
       
       var isAndroid = false;
       if (Titanium.Platform.name == 'android') {
       	isAndroid = true;
       }
       
       //
       // CREATE ANNOTATIONS
       //
       
       var atlantaParams = {
       		latitude:33.74511,
       		longitude:-84.38993,
       		title:"Atlanta, GA",
       		subtitle:'Atlanta Braves Stadium\nfoo',
       		animate:true,
       		rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE,
       		myid:3 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS
       	};
       
       atlantaParams.pincolor = Titanium.Map.ANNOTATION_PURPLE;
       var atlanta = Titanium.Map.createAnnotation(atlantaParams);
       
       //
       // PRE-DEFINED REGIONS
       //
       var regionAtlanta = {latitude:33.74511,longitude:-84.38993,animate:true,latitudeDelta:0.04, longitudeDelta:0.04};
       
       //
       // CREATE MAP VIEW
       //
       var mapview = Titanium.Map.createView({
       	mapType: Titanium.Map.STANDARD_TYPE,
       	region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
       	animate:true,
       	regionFit:true,
       	userLocation:true,
       	annotations:[atlanta]
       });
       mapview.addEventListener("click", function(e) {
       	Ti.API.info("ANNOTATION CLICKED:" + e.title + ":" + e.subtitle + ":" + e.longitude + ":" + e.latitude + ":" + e.annotation + ":" + e.clicksource);
       });
       
       if (!isAndroid) {
       	mapview.addAnnotation(atlanta);
       }
       mapview.selectAnnotation(atlanta);
       win.add(mapview);
       
       //
       // NAVBAR BUTTONS
       //
       
       var removeAll = null;
       var atl = null;
       var sv = null;
       var sat = null;
       var std = null;
       var hyb = null;
       var zoomin = null;
       var zoomout = null;
       		
       var wireClickHandlers = function() {
       	removeAll.addEventListener('click', function() {
       		mapview.removeAllAnnotations();
       	});
       
       	atl.addEventListener('click', function() {
       		// set location to atlanta
       		mapview.setLocation(regionAtlanta);
       	
       		// activate annotation
       		mapview.selectAnnotation(mapview.annotations[0].title,true);
       		Ti.API.error("CLICKED ATL");
       	});
       	
       	sv.addEventListener('click', function() {
       		Ti.API.info('IN SV CHANGE');
       		// set location to sv
       		mapview.setLocation(regionSV);
       	
       		// activate annotation
       		mapview.selectAnnotation(mapview.annotations[1].title,true);
       	});
       	
       	sat.addEventListener('click',function() {
       		// set map type to satellite
       		mapview.setMapType(Titanium.Map.SATELLITE_TYPE);
       	});
       	
       	std.addEventListener('click',function() {
       		// set map type to standard
       		mapview.setMapType(Titanium.Map.STANDARD_TYPE);
       	});
       	
       	hyb.addEventListener('click',function() {
       		// set map type to hybrid
       		mapview.setMapType(Titanium.Map.HYBRID_TYPE);
       	});
       	
       	zoomin.addEventListener('click',function() {
       		mapview.zoom(1);
       	});
       	
       	zoomout.addEventListener('click',function() {
       		mapview.zoom(-1);
       	});
       };
       
       if (!isAndroid) {
       	removeAll = Titanium.UI.createButton({
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
       		title:'Remove All'
       	});
       	win.rightNavButton = removeAll;
       
       	//
       	// TOOLBAR BUTTONS
       	//
       	
       	// button to change to ATL
       	atl = Titanium.UI.createButton({
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
       		title:'ATL'
       	});
       	// activate annotation
       	mapview.selectAnnotation(mapview.annotations[0].title,true);
       	
       	// button to change to SV	
       	sv = Titanium.UI.createButton({
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
       		title:'SV'
       	});
       	mapview.addEventListener('complete', function()
       	{
       		Ti.API.info("map has completed loaded region");
       	});
       	
       	
       	var flexSpace = Titanium.UI.createButton({
       		systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
       	});
       	
       	// button to change map type to SAT
       	sat = Titanium.UI.createButton({
       		title:'Sat',
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
       	});
       	// button to change map type to STD
       	std = Titanium.UI.createButton({
       		title:'Std',
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
       	});
       	// button to change map type to HYBRID
       	hyb = Titanium.UI.createButton({
       		title:'Hyb',
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
       	});
       	// button to zoom-in
       	zoomin = Titanium.UI.createButton({
       		title:'+',
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
       	});
       	// button to zoom-out
       	zoomout = Titanium.UI.createButton({
       		title:'-',
       		style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
       	});
       	
       	wireClickHandlers();
       	
       	win.setToolbar([flexSpace,std,flexSpace,hyb,flexSpace,sat,flexSpace,atl,flexSpace,sv,flexSpace,zoomin,flexSpace,zoomout,flexSpace]);
       } else {
       	var activity = Ti.Android.currentActivity;
       	activity.onCreateOptionsMenu = function(e) {
       		var menu = e.menu;
       		
       		atl = menu.add({title : 'ATL'});
       		sv = menu.add({title : 'SV'});
       		sat = menu.add({title : 'Sat'});
       		std = menu.add({title : 'Std'});
       		hyb = menu.add({title : 'Hyb'});
       		zoomin = menu.add({title : "Zoom In"});
       		zoomout = menu.add({title : 'Zoom Out'});
       		removeAll = menu.add({title:'Remove All'});
       		
       		wireClickHandlers();
       	};
       }
       
       //
       // EVENT LISTENERS
       //
       
       // region change event listener
       mapview.addEventListener('regionChanged',function(evt)
       {
       	Titanium.API.info('maps region has updated to '+evt.longitude+','+evt.latitude);
       });
       
       win.open();
       
       
    When running the app, if you click on the pin itself you will see the popup toggle and a log statement from the click handler indicate "pin" as te click source. If you click the popup then the click source will indicate "title" or "subtitle" and the popup will remain.
  2. Eric Merriman 2012-01-19

    Verified fixed with SDK 1.9.0.v20120119134634 on Nexus S (2.3.6) and emulator 2.3.1
  3. Wilson Luu 2012-01-31

    updated labels

JSON Source