Phonegapを使用してAndroidデバイスの向きを度(地面に対する電話の角度)で取得できるかどうかを誰かに教えてもらえますか?また、磁場も取得できますか?
9343 次
3 に答える
13
コンパスは、デバイスが向けられている方向または方向を検出するセンサーです。方位を0度から359.99度で測定します。
コンパスの見出し情報は、compassSuccessコールバック関数を使用してCompassHeadingオブジェクトを介して返されます。
function onSuccess(heading) {
alert('Heading: ' + heading.magneticHeading);
};
function onError(error) {
alert('CompassError: ' + error.code);
};
navigator.compass.getCurrentHeading(onSuccess, onError);
電話のx、y、またはz軸の回転角度にアクセスする場合は、ベアHTML5を使用できます。これはそれについての素晴らしい記事です:この終わり:デバイスの向きの使用
コード例:
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha
// deviceorientation does not provide this data
var motUD = null;
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir, motUD);
}, false);
于 2012-12-18T14:25:44.503 に答える
1
html5を使用してデバイスの向きを判断することが可能です
詳細については、こちらをご覧ください。
html5 / phonegapを使用して加速度計を使用できるため、方向の角度とそのようなすべてのデータを取得できます。
于 2012-12-18T14:25:30.667 に答える