Domanda

Qualcuno può aiutarmi con come ruotare la testa della freccia in Google Map V2? Hai visto che in nettaio la testa della freccia sta ruotando nella direzione che affrontiamo. Voglio implementarlo nella mia app. Sono rosso markerOption.rotation(rotation) Questo sembra statico. Voglio ruotare dinamicamente la freccia quando ruoto il telefono.

È stato utile?

Soluzione

Sono stato in grado di farlo. È così facile. Di seguito è come. Questo per leggere il sensore e ottenere l'orientamento del telefono.

/**
 * Initialize the sensor manager.
 */
private void setupSensorManager() {
    mSensorManager = (SensorManager) mContext
            .getSystemService(Context.SENSOR_SERVICE);
    mSensorManager.registerListener(mSensorListener,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_NORMAL);

    Log.d(TAG, "SensorManager setup");
}

/**
 * The sensor event listener.
 */
SensorEventListener mSensorListener = new SensorEventListener() {

    @Override
    public void onSensorChanged(SensorEvent event) {
        mOrientation = event.values[0];
        Log.d(TAG, "Phone Moved "+mOrientation);
        draw(mOrientation);
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }
};

Ed è qui che ruoto davvero. Il mio indicatore è già aggiunto alla mappa. E lo accedo da un'altra classe.

public void draw(float angle) {
            // Take the relevant Marker from the marker list where available in map
    AndroidMapGoogleOverlayItem myself = (AndroidMapGoogleOverlayItem) getOverlayItem(0);

    if (myself == null) {
        return;
    }
    myself.getMarker().setRotation(mOrientation);  // set the orientation value returned from the senserManager
 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top