In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Geolocator AS3 AIR API

It is meant for Adobe AIR for android devices
that do not have the magnetometer but do have GPS. It will show current traveled 
direction in degrees. 0-360 is North, 90 is East, 180 is South, and 270 is West
Get Adobe Flash player
by Catttdaddy 11 Sep 2013
    Embed
/**
 * Copyright Catttdaddy ( http://wonderfl.net/user/Catttdaddy )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/mf9A
 */

/* Thanks to Floris for all of his help from Stackoverflow for his help in gettnig this working.. 
I was seriously stuck at a few parts!
Code is cut up so that it functions here. It is meant for Adobe AIR for android devices
that do not have the magnetometer but do have GPS. It will show current traveled 
direction in degrees. 0-360 is North, 90 is East, 180 is South, amd 270 is West
*/


package 

{
import flash.display.Sprite;
// Geolocation sensor stuff
import flash.sensors.Geolocation; 
import flash.events.GeolocationEvent;
//Timer setup stuff for setting frequesncy of GPS Update
import flash.utils.Timer;
import flash.events.TimerEvent;

// Sprite and Textfield display
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;


    public class FlashTest extends Sprite 

    {
        //Variable to check if current or prior Geolocation Event fired and if to log in gpsLat1/gpsLon1 or gpsLat2/gpsLon2
        // The "if/else" has been removed from this snipet.
        private var gpsCheck:int = 1;
        public var dLon:Number
        

        //latitude and longitude in degrees (RAW info from Geolocation)
        public var gpsLat1:Number
        public var gpsLon1:Number
        private var gpsLat2:Number
        private var gpsLon2:Number
        public var bearing:Number
        

        // Latitude and longitude in radians converted from Degrees
        public var gpsLat1R:Number
        public var gpsLon1R:Number
        private var gpsLat2R:Number
        private var gpsLon2R:Number     
        private var yy:Number  
        private var xx:Number          
        

        public function FlashTest() 

        {
            // Text box for displaying results
            var my_txt:TextField = new TextField();
                my_txt.wordWrap=true; 
                my_txt.width = 300;
                my_txt.height = 300;
                 addChild(my_txt);
                 
            // Commented this ot as Geolocation is not on Wonderfl
            /*
            //If GPS is on device create Geolocation object named "my_geo"
            //Request updates from my_geo every 2000 milliseconds. Run onGeoUpdate function
            //when Event is triggered. After that create the text box for displaying data.
            if (Geolocation.isSupported)
            {
                var my_geo:Geolocation = new Geolocation();
                my_geo.setRequestedUpdateInterval(2000);                
                my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
                var my_txt:TextField = new TextField();
                my_txt.wordWrap=true; 
                my_txt.width = 300;
                my_txt.height = 300;
                addChild(my_txt);
            } 
            // If GPS is not supported on device display "No GPS Signal" 
            else
            {
                addChild(my_txt);
                my_txt.wordWrap=true; 
                my_txt.width = 300;
                my_txt.height = 300;
                addChild(my_txt);
                my_txt.text = "No GPS Signal ";
            }
            */
            
            
            // False GPS reading being passed for testing 
            //COMMENT THESE LINES OUT STARTING HERE---
                gpsLat1 =  42.1234584;
                gpsLon1 = -83.1234577;
                gpsLat2 =  42.1234583;
                gpsLon2 = -83.1234577;
           // END OF WHAT SHOULD BE COMMENTED OUT---
           
           // Equations to convert all RAW Geolocation information over to radians 
                gpsLat1R = gpsLat1 * Math.PI / 180;
                gpsLon1R = gpsLon1 * Math.PI / 180;
                gpsLat2R = gpsLat2 * Math.PI / 180;
                gpsLon2R = gpsLon2 * Math.PI / 180;
          // The rest of the math     
                dLon = gpsLon1 - gpsLon2;
                yy = Math.sin(dLon) * Math.cos(gpsLat2R);
                xx = Math.cos(gpsLat1R) * Math.sin(gpsLat2R) - Math.sin(gpsLat1R) * Math.cos(gpsLat2R) * Math.cos(dLon);
                bearing = Math.atan2(yy, xx) * 180 / Math.PI;
         // Run The Geoupdate function                
            onGeoUpdate();
            
            
        // Geoupdate basically displays the information that was collected and converted.
        // This is where you will put what you want the code to do with the results
            function onGeoUpdate():void
            {
            my_txt.text = "My Latitude is "+gpsLat1+ " and my Longitude is "+gpsLon1+ 
            "My 2nd Latitude is "+gpsLat2+" and my 2nd Longitude is "+gpsLon2+ 
            " Bearing is " +bearing;
          
            }            
        }
    }
}