Pregunta

Desarrollé una aplicación híbrida usando phonegap.

Uso de la función Compás en API de PhoneGAP y código nativo.

Hay un problema.

Mis dispositivos de prueba (Galaxy Note 1, Galaxys3, etc ...) no indican la misma dirección.

Mi fuente de phonegap es ...

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
        startWatch();
    }

function startWatch() {

        // Update compass every 3 seconds
        var options = { frequency: 1000 };

        watchID = navigator.compass.watchHeading(onSuccess, onError, options);
    }

function onSuccess(heading) {
        var element = document.getElementById('heading');
        var deg = heading.magneticHeading;
        element.innerHTML = 'Heading: ' + deg + '<br>';        
    }

API de referencia de phonegap.

Mi fuente nativa es ...

float[] mGravity;
float[] mGeomagnetic;

public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        mGravity = event.values.clone();
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
        mGeomagnetic = event.values.clone();
    if (mGravity != null && mGeomagnetic != null) {
        float R[] = new float[9];
        float I[] = new float[9];
        boolean success = SensorManager.getRotationMatrix(R, I, mGravity,     mGeomagnetic);
        if (success) {
        float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            azimut = (float)Math.toDegrees(orientation[0]);

            //for (-180 to 180), (-10 to 350) 
            if(azimut<0)
                azimut = azimut+360;                            Log.d("azimut",""+azimut);

            // orientation contains: azimut, pitch and roll
            Matrix matrix=new Matrix();
            imgView.setScaleType(ScaleType.MATRIX);   //required
            matrix.postRotate(360-azimut+angle, imgView.getWidth()/2,     imgView.getHeight()/2);
            imgView.setImageMatrix(matrix);

        }
    }
}

Referencia de Google Developer.

¿Por qué mis dispositivos no pueden indicar la misma dirección?

¿Fue útil?

Solución

Considerando en sus comentarios que indique que es su brújula y no su código, la respuesta es recalibrar su brújula.Por favor vea las instrucciones vinculadas: http://forum.xda-developers.com/showthread.php?t=1778131

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top