AS3: Calculating MPH using GeoLocation (version 2)


/ Published in: ActionScript 3
Save to your folder(s)

Here's a more OOP version


Copy this code and paste it in your HTML
  1. package
  2. {
  3. import flash.desktop.*;
  4. import flash.display.*;
  5. import flash.events.*;
  6. import flash.sensors.*;
  7. import flash.system.*;
  8.  
  9. public class Main extends Sprite
  10. {
  11. static private const CONVERSION_BASE :Number = 2.2369362920544;
  12.  
  13. public function Main( )
  14. {
  15. if( Geolocation.isSupported ){
  16. geolocation = new GeolocationReal();
  17. geolocation.setRequestedUpdateInterval( 1000 );
  18. geolocation.addEventListener( GeolocationEvent.UPDATE, handleGeolocationUpdate );
  19.  
  20. }
  21. }
  22.  
  23. private function convertToMilesPerHour( metresPerSecond :Number ) :Number
  24. {
  25. return metresPerSecond * CONVERSION_BASE;
  26. }
  27.  
  28. private function handleGeolocationUpdate( e :GeolocationEvent ) :void
  29. {
  30. var mph:Number = Math.round( convertToMilesPerHour( e.speed );
  31. trace( "mph:", mph );
  32. }
  33. }
  34. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.