Search code examples
iphoneweb-applicationsaccelerometeruiaccelerometer

Is it possible for a web app to gather an iPhone's accelerometer data? If so, how?


Is it possible for a web app to gather an iPhone's accelerometer data? If so, how? I would think they might have in the Safari Web browser an API with such functionality.

If it is possible could someone send me a link to pages with specific coding information.


Solution

  • Found this snippet from here with a bit of Googling.

    window.ondevicemotion = function(event) {
      ax = event.accelerationIncludingGravity.x
      ay = event.accelerationIncludingGravity.y
      az = event.accelerationIncludingGravity.z
      rotation = event.rotationRate;
      if (rotation != null) {
        arAlpha = Math.round(rotation.alpha);
        arBeta = Math.round(rotation.beta);
        arGamma = Math.round(rotation.gamma);
      }
    }