Posted By

chrisaiv on 11/15/11


Tagged

as3


Versions (?)

AS3: Calculating MPH using GeoLocation (version 1)


 / Published in: ActionScript 3
 

There are ways to calculate speed and altitude using the GeoLocation class. In the US, you can even calculate Miles Per Hour.

  1. var geo:Geolocation = new Geolocation();
  2. geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
  3. function geolocationUpdateHandler(e:GeolocationEvent):void
  4. {
  5. var altitude:Number = e.altitude;
  6. //Meters Per Second
  7. var mps:Number = e.speed;
  8. //Miles Per Hour
  9. var mph:Number = Math.round( (mps * 360000) / 160934.4 ) );
  10. trace( "altitude:", altitude, "meters per second:", mps, "miles per hour:", mph );
  11. }

Report this snippet  

You need to login to post a comment.