Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10921] iOS: Ti.Geolocation 'location' event doesn't play nice with getCurrentPosition method

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-10-05T17:32:16.000+0000
Affected Version/sRelease 2.1.2, Release 3.0.0
Fix Version/sRelease 3.0.0, Sprint 2012-20 API, 2012 Sprint 20
ComponentsiOS
LabelsSupportTeam, api, qe-port
ReporterEduardo Gomez
AssigneePing Wang
Created2012-09-14T14:17:10.000+0000
Updated2012-12-04T19:28:46.000+0000

Description

Problem

Ti.Geolocation.getCurrentPosition() method does not work in conjunction with a Ti.Geolocation.addEventListener('location', ...), the getCurrentPosition callback event is never called.

Tested on

iOS simulator 5.1 & iphone 4

Steps to reproduce

1. run the code. No pause/resume events needed. 2. From a fresh launch, the button will do nothing if line 40 is uncommented.

Repro sequence

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

var win = Titanium.UI.createWindow({  
  	title: 'test'
});

Ti.Geolocation.trackSignificantLocationChange = true;
Titanium.Geolocation.distanceFilter = 10;
Titanium.Geolocation.purpose = "Testing";

var n=0, notification = [];
var locationCallback = function(e){
	var longitude = e.coords.longitude;
    var latitude = e.coords.latitude;
    
	notification[n] = Titanium.App.iOS.scheduleLocalNotification({ 
		alertBody: 'long: ' + longitude + '\nlat: ' + latitude,
		alertAction:"View App",
		userInfo:{"hello":"world"},
		date: new Date()
	});
	//alert(e)
	n++;
};

var btn = Ti.UI.createButton({
	title: 'Get Location',
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE
});
win.add(btn);

btn.addEventListener('click', function(){
	Ti.Geolocation.getCurrentPosition(function(e){		    
	    alert(e.coords);
	});
})

//Ti.Geolocation.addEventListener('location', locationCallback);

win.open();

Comments

  1. Ping Wang 2012-09-25

    PR https://github.com/appcelerator/titanium_mobile/pull/3041
  2. Sabil Rahim 2012-10-05

    CR & FR
  3. Natalie Huynh 2012-12-04

    Tested with 3.0.0.v20121130200208 on iPhone 4 5.1.1

JSON Source