/ Published in: ActionScript 3
Here's a more OOP version
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 ); } } }
URL: http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/