[TIMOB-5602] MobileWeb: Ti.Geolocation: getCurrentPosition can not define location when event listener defined for event 'location'
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-06-17T01:03:45.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | MobileWeb |
Labels | n/a |
Reporter | Misha Vasko |
Assignee | Maxim Negadaylov |
Created | 2011-06-16T06:51:31.000+0000 |
Updated | 2017-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);
Closing ticket as fixed.