Return to Snippet

Revision: 53154
at November 15, 2011 04:52 by chrisaiv


Initial Code
package 
{
	import flash.desktop.*;
	import flash.display.*;
	import flash.events.*;
	import flash.sensors.*;
	import flash.system.*;

	public class Main extends Sprite
	{
        static private const CONVERSION_BASE :Number = 2.2369362920544;
		
		public function Main(  )
		{
			if( Geolocation.isSupported ){
                geolocation = new GeolocationReal();
                geolocation.setRequestedUpdateInterval( 1000 );
                geolocation.addEventListener( GeolocationEvent.UPDATE, handleGeolocationUpdate );
			    
			}
		}

        private function convertToMilesPerHour( metresPerSecond :Number ) :Number
        {
            return metresPerSecond * CONVERSION_BASE;
        }

        private function handleGeolocationUpdate( e :GeolocationEvent ) :void
        {
         var mph:Number = Math.round( convertToMilesPerHour( e.speed );
         trace( "mph:", mph );
        }
    }
}

Initial URL
http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/

Initial Description
Here's a more OOP version

Initial Title
AS3: Calculating MPH using GeoLocation (version 2)

Initial Tags


Initial Language
ActionScript 3