Азимут GPS на какой шкале

  • В какой шкале location.getBearing()возвращает угол, это от 0 до 360 градусов к востоку от севера или в какой-то другой шкале.

  • Должен ли курс моего телефона с истинным севером соответствовать этому азимуту, если мой телефон расположен параллельно направлению движения?

Я рассчитываю азимут с помощью функции SensorManager.getOrientation(rotationMatrix,vals) и добавляю к нему склонение GPS, чтобы получить направление устройства с истинным севером.


person Paras Dhawan    schedule 07.05.2015    source источник
comment
вот что вы ищете ссылка это мне очень помогло.!!   -  person Kishore Jethava    schedule 07.05.2015
comment
@kishorejethava, но я все еще в замешательстве...   -  person Paras Dhawan    schedule 07.05.2015
comment
@kishorejethava, потому что в некоторых случаях направление устройства и азимут GPS не совпадают.   -  person Paras Dhawan    schedule 07.05.2015


Ответы (2)


Это то, что я сделал, вы можете ссылаться на этот код.

при изменении датчика

@Override
        public void onSensorChanged(SensorEvent event) {
            // TODO Auto-generated method stub
            if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
                mGeomagnetic = event.values;
            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
                mGravity = event.values;

            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 = orientation[0]; // orientation contains:
                                                // azimut, pitch and roll
                    rotateCompass(azimut);
                }
            }
        }

Рассчитать пеленг

private void rotateCompass(final float azimut) {

    float azimuth = (float) Math.round(Math.toDegrees(azimut));
    Location currentLoc = new Location("");
    currentLoc.setLatitude(curr_lat);
    currentLoc.setLongitude(curr_long);
    Location target = new Location("");
    target.setLatitude(dest_lat);
    target.setLongitude(dest_lng);

    float bearing = currentLoc.bearingTo(target); // (it's already in degrees)
    if (bearing < 0) {
        bearing = bearing + 360;
    }
    float direction = (float) (bearing - azimuth);

     // If the direction is smaller than 0, add 360 to get the rotation clockwise.
    if (direction < 0) {
        direction = direction + 360;
    }

    showToast("" + direction);
    rotateImageView(imgCompass, R.drawable.pin_finder, direction);
}

Повернуть изображение в соответствии с направлением в градусах

private void rotateImageView(ImageView imageView, int drawable, float rotate) {

    // Decode the drawable into a bitmap
    Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
            drawable);
    // Get the width/height of the drawable
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = bitmapOrg.getWidth(), height = bitmapOrg.getHeight();

    // Initialize a new Matrix
    Matrix matrix = new Matrix();

    // Decide on how much to rotate
    rotate = rotate % 360;

    // Actually rotate the image
    matrix.postRotate(rotate, width, height);

    // recreate the new Bitmap via a couple conditions
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
            height, matrix, true);
    // BitmapDrawable bmd = new BitmapDrawable( rotatedBitmap );

    // imageView.setImageBitmap( rotatedBitmap );
    imageView.setImageDrawable(new BitmapDrawable(getResources(),
            rotatedBitmap));
    imageView.setScaleType(ScaleType.CENTER);
}
person Kishore Jethava    schedule 07.05.2015
comment
Я уже пробовал это, но мой вопрос все еще остается без ответа/ - person Paras Dhawan; 09.05.2015
comment
@ParasDhawan посмотрите это видео здесь, чтобы узнать истинное направление, вы можете поискать больше видео - person Kishore Jethava; 09.05.2015

person    schedule
comment
@AlecWien Да, в первой части я понял, что азимут находится в диапазоне от 0 до 359,9999 от истинного севера по часовой стрелке, но я все еще запутался во второй ... не могли бы вы уточнить, пожалуйста. - person Paras Dhawan; 09.05.2015