Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-12234

BlackBerry: Implement important Titanium.Geolocation functionality

    Details

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                penrique Pedro Enrique (Inactive)
                Reporter:
                rmcmahon Russell McMahon
                Reviewer:
                Pedro Enrique (Inactive)
              • Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration