Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5602] MobileWeb: Ti.Geolocation: getCurrentPosition can not define location when event listener defined for event 'location'

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-06-17T01:03:45.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsMobileWeb
Labelsn/a
ReporterMisha Vasko
AssigneeMaxim Negadaylov
Created2011-06-16T06:51:31.000+0000
Updated2017-03-09T20:50:34.000+0000

Description

getCurrentPosition method of Ti.Geolocation can not define location when event listener defined for event 'location'.
var win = Titanium.UI.currentWindow;
win.backgroundColor = '#fff';

function locationCallback(e){
	if (!e.success || e.error) {
		l.text = 'error: ' + e.error + ' code ' + e.code
		return;
	}

	var longitude = e.coords.longitude;
	var latitude = e.coords.latitude;
	var altitude = e.coords.altitude;
	var heading = e.coords.heading;
	var accuracy = e.coords.accuracy;
	var speed = e.coords.speed;
	var timestamp = e.coords.timestamp;
	var altitudeAccuracy = e.coords.altitudeAccuracy;
	l.text = ' long: ' + longitude + '\n lat: ' + latitude + '\n alt: ' + altitude + '\n heading: ' + heading + '\n accuracy: ' + accuracy + '\n speed: ' + speed + '\n timestamp: ' + timestamp + '\n altitude accuracy: ' + altitudeAccuracy;
}

Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;

var l = Ti.UI.createLabel({
	font:{fontSize:14},
	color:'#000',
	top:10,
	left:10,
	height:190,
	width:300
});
Ti.UI.currentWindow.add(l);
function geoAlert(){
	alert('Data received');
};
Ti.Geolocation.addEventListener('location',geoAlert);

var currentPosButton = Ti.UI.createButton({
	title:'Get Current Position',
	height:40,
	top:200,
	left:10,
	width:300,
	font:{fontSize:20}
});
Ti.UI.currentWindow.add(currentPosButton);


currentPosButton.addEventListener('click', function() {
	l.text = '';
	Titanium.Geolocation.getCurrentPosition(locationCallback);

});
If we remove from test this piece of code we can get our location by clicking 'Get Current Position'
function geoAlert(){
	alert('Data received');
};
Ti.Geolocation.addEventListener('location',geoAlert);

Comments

  1. Lee Morris 2017-03-09

    Closing ticket as fixed.

JSON Source