peter9477

PlayBook GPS tracking test app

May 13th, 2011
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. package {
  2. import caurina.transitions.Tweener;
  3.  
  4. import flash.display.Sprite;
  5. import flash.display.Screen;
  6. import flash.display.StageAlign;
  7. import flash.display.StageScaleMode;
  8.  
  9. import flash.events.StatusEvent;
  10. import flash.events.GeolocationEvent;
  11. import flash.sensors.Geolocation;
  12.  
  13. import flash.text.TextFieldAutoSize;
  14. import flash.utils.*;
  15.  
  16. import mx.utils.ObjectUtil;
  17.  
  18. import qnx.ui.text.Label;
  19. import qnx.system.QNXSystemResource;
  20. import qnx.system.QNXSystem;
  21.  
  22. [SWF(backgroundColor="#cccccc")]
  23. public class GeolocationTest extends Sprite {
  24. private var label:Label = new Label();
  25.  
  26. private var geo:Geolocation;
  27. private var base_time:int = getTimer();
  28.  
  29. public function GeolocationTest() {
  30. stage.align = StageAlign.TOP_LEFT;
  31. stage.scaleMode = StageScaleMode.NO_SCALE;
  32.  
  33. label.autoSize = TextFieldAutoSize.LEFT;
  34. label.x = 10;
  35. label.y = 10;
  36. label.text = "Just walk away.";
  37. addChild(label);
  38.  
  39. if (!Geolocation.isSupported) {
  40. label.text = 'Geolocation not supported!';
  41. trace(label.text);
  42. return;
  43. }
  44.  
  45. geo = new Geolocation();
  46.  
  47. // muted would mean user didn't grant permission for read_geolocation
  48. if (geo.muted) {
  49. label.text = 'Geolocation muted';
  50. trace(label.text);
  51. }
  52.  
  53. geo.setRequestedUpdateInterval(5000);
  54.  
  55. // when unit goes to standby, gets STATUS event wiht Geolocation.Unmuted
  56. // and when out of standby, says Geolocation.Muted!
  57. geo.addEventListener(StatusEvent.STATUS, onStatusEvent);
  58.  
  59. geo.addEventListener(GeolocationEvent.UPDATE, onGeolocationEvent);
  60.  
  61. trace(getTimer(), ObjectUtil.toString(QNXSystem.system.getResources()));
  62. QNXSystem.system.requestResource(QNXSystemResource.GEOLOCATION);
  63. trace('after request', ObjectUtil.toString(QNXSystem.system.getResources()));
  64. }
  65.  
  66. private function onStatusEvent(e:StatusEvent):void {
  67. trace(getTimer(), e.type, e.code, e.target, geo.muted);
  68. }
  69.  
  70. private var done_first:Boolean;
  71. private function onGeolocationEvent(e:GeolocationEvent):void {
  72. if (!done_first) {
  73. done_first = true;
  74. trace(getTimer(), 'FIRST', e.timestamp.toFixed(6), e.type);
  75. }
  76.  
  77. var msg:String = e.timestamp.toFixed(6) + ': (' +
  78. e.latitude.toFixed(6) + ', ' +
  79. e.longitude.toFixed(6) + ', ' +
  80. int(e.altitude).toString() + 'm) / +/- ' +
  81. e.horizontalAccuracy.toFixed(1) + 'm/' +
  82. e.verticalAccuracy.toFixed(1) + 'm, ' +
  83. e.speed.toFixed(2) + 'm/s, ' +
  84. e.heading.toFixed(1) + '\u00b0';
  85.  
  86. label.text = msg;
  87. trace(msg);
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment