Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import caurina.transitions.Tweener;
- import flash.display.Sprite;
- import flash.display.Screen;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.StatusEvent;
- import flash.events.GeolocationEvent;
- import flash.sensors.Geolocation;
- import flash.text.TextFieldAutoSize;
- import flash.utils.*;
- import mx.utils.ObjectUtil;
- import qnx.ui.text.Label;
- import qnx.system.QNXSystemResource;
- import qnx.system.QNXSystem;
- [SWF(backgroundColor="#cccccc")]
- public class GeolocationTest extends Sprite {
- private var label:Label = new Label();
- private var geo:Geolocation;
- private var base_time:int = getTimer();
- public function GeolocationTest() {
- stage.align = StageAlign.TOP_LEFT;
- stage.scaleMode = StageScaleMode.NO_SCALE;
- label.autoSize = TextFieldAutoSize.LEFT;
- label.x = 10;
- label.y = 10;
- label.text = "Just walk away.";
- addChild(label);
- if (!Geolocation.isSupported) {
- label.text = 'Geolocation not supported!';
- trace(label.text);
- return;
- }
- geo = new Geolocation();
- // muted would mean user didn't grant permission for read_geolocation
- if (geo.muted) {
- label.text = 'Geolocation muted';
- trace(label.text);
- }
- geo.setRequestedUpdateInterval(5000);
- // when unit goes to standby, gets STATUS event wiht Geolocation.Unmuted
- // and when out of standby, says Geolocation.Muted!
- geo.addEventListener(StatusEvent.STATUS, onStatusEvent);
- geo.addEventListener(GeolocationEvent.UPDATE, onGeolocationEvent);
- trace(getTimer(), ObjectUtil.toString(QNXSystem.system.getResources()));
- QNXSystem.system.requestResource(QNXSystemResource.GEOLOCATION);
- trace('after request', ObjectUtil.toString(QNXSystem.system.getResources()));
- }
- private function onStatusEvent(e:StatusEvent):void {
- trace(getTimer(), e.type, e.code, e.target, geo.muted);
- }
- private var done_first:Boolean;
- private function onGeolocationEvent(e:GeolocationEvent):void {
- if (!done_first) {
- done_first = true;
- trace(getTimer(), 'FIRST', e.timestamp.toFixed(6), e.type);
- }
- var msg:String = e.timestamp.toFixed(6) + ': (' +
- e.latitude.toFixed(6) + ', ' +
- e.longitude.toFixed(6) + ', ' +
- int(e.altitude).toString() + 'm) / +/- ' +
- e.horizontalAccuracy.toFixed(1) + 'm/' +
- e.verticalAccuracy.toFixed(1) + 'm, ' +
- e.speed.toFixed(2) + 'm/s, ' +
- e.heading.toFixed(1) + '\u00b0';
- label.text = msg;
- trace(msg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment