AS3: Calculating MPH using GeoLocation (version 1)


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.