Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12234] BlackBerry: Implement important Titanium.Geolocation functionality

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-05-25T05:12:08.000+0000
Affected Version/sRelease 3.3.0
Fix Version/s2013 Sprint 10 BB, Release 3.3.0, Release 3.4.0
ComponentsBlackBerry
Labelsnotable, qe-3.3.0, qe-closed-3.2.0, qe-testadded
ReporterRussell McMahon
AssigneePedro Enrique
Created2013-01-07T13:18:54.000+0000
Updated2014-05-30T17:05:12.000+0000

Description

Acceptance Tests

Location event

var win = Ti.UI.createWindow({
	layout: 'vertical'
});

if (!Ti.Geolocation.locationServicesEnabled) {
	alert('Please enable location services.');
}

function onLocation(e) {
    coordLabels[0].text = 'lat: ' + e.coords.latitude;
    coordLabels[1].text = 'long: ' + e.coords.longitude;
}

var geoEnabled = false;
function toggleGeo() {
	geoEnabled = !geoEnabled;
	geoEnabled ? Ti.Geolocation.addEventListener('location', onLocation)
		   : Ti.Geolocation.removeEventListener('location', onLocation);
}

var toggleButton = Ti.UI.createButton({
	title: 'Toggle Geolocation'
});
toggleButton.addEventListener('click', toggleGeo);
win.add(toggleButton);

var coordLabels = ['lat', 'long'].map(function(text) {
	var label = Ti.UI.createLabel({
		text: text,
		width: Ti.UI.FILL
	});
	win.add(label);
	return label;
});

win.open();
Verify when you click the toggle button your current position is displayed and updated as you move. Clicking the toggle again should turn off updates. Repeat a few times to verify it switches on/off.

Heading event

var win = Ti.UI.createWindow({
	layout: 'vertical'
});

var headingLabel = Ti.UI.createLabel({
	text: 'heading = ',
	width: Ti.UI.FILL
});
win.add(headingLabel);

var accuracyLabel = Ti.UI.createLabel({
	text: 'accuracy = ',
	width: Ti.UI.FILL
});
win.add(accuracyLabel);

function onHeading(e) {
	headingLabel.text = 'heading = ' + e.heading.magneticHeading;
	accuracyLabel.text = 'accuracy = ' + e.heading.accuracy;
}

var compassEnabled = false;
function toggleCompass() {
	compassEnabled = !compassEnabled;
	compassEnabled ? Ti.Geolocation.addEventListener('heading', onHeading)
	               : Ti.Geolocation.removeEventListener('heading', onHeading);
}

var toggleButton = Ti.UI.createButton({
	title: 'Toggle Compass'
});
toggleButton.addEventListener('click', toggleCompass);
win.add(toggleButton);

win.open();
Verify clicking the toggle button starts displaying compass heading values. Try rotating the phone to verify the degrees changes. Click the toggle again to verify the compass events stop.

Comments

  1. Josh Roesslein 2013-05-09

    Created pull request [#36](https://github.com/appcelerator/titanium_mobile_blackberry/pull/36).
  2. Olga Romero 2013-12-10

    Tested with: Appcelerator Studio, build: 3.2.0.201312081316 Titanium SDK, build: 3.2.0.v20131209110113 CLI 3.2.0-beta BlackBerry Z10 10.1.0.2019

    To test

    add to tiapp.xml
       <blackberry>
           	<permissions>
           <permission>access_internet</permission>
           <permission>access_location_services</permission>
       		</permissions>
           </blackberry>
       
  3. Olga Romero 2014-05-23

    To test

    Run the code below and click the toggle geolocation button http://pastie.org/private/vnc7cbbs0vg1ziwqdof6tq

    Environment

    Appcelerator Studio, build: 3.3.0.201405161313 Titanium SDK, build: 3.3.0.v20140523120121 Node.JS Version: v0.10.13 NPM Version: 1.3.2 acs@1.0.14 alloy@1.4.0-alpha4 npm@1.3.2 titanium@3.3.0-alpha5 titanium-code-processor@1.1.1 Device: BB Z10 (10.2.1)

    the error

       [ERROR] trace = TypeError: Cannot read property 'latitude' of undefined
       [ERROR]     at [object Object].onLocation (app.js:18:45)
       [ERROR] line = 18
       
  4. Pedro Enrique 2014-05-25

    PR for master: https://github.com/appcelerator/titanium_mobile_blackberry/pull/246 PR for 3.3.X https://github.com/appcelerator/titanium_mobile_blackberry/pull/247
  5. Olga Romero 2014-05-30

    Tested with Mac osx 10.9.3 Mavericks Appcelerator Studio, build: 3.3.0.201405271647 Titanium SDK, build: 3.3.0.v20140528144113 Node.JS Version: v0.10.13 NPM Version: 1.3.2 acs@1.0.14 alloy@1.4.0-beta npm@1.3.2 titanium@3.3.0-beta titanium-code-processor@1.1.1 Device: BB Z10 (10.2.1) Verified clicking the toggle button starts displaying compass heading values. Rotated the phone to verify the degrees changes. Clicked the toggle again to verify the compass events stop.

JSON Source