首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >全球定位系统的刻度

全球定位系统的刻度
EN

Stack Overflow用户
提问于 2015-05-07 06:01:27
回答 2查看 445关注 0票数 0
  • location.getBearing()在哪个尺度上返回角度,它是从0到360度的东经偏北,还是在其他尺度上。
  • 如果我的手机与移动方向平行的话,我的手机的方位是否需要匹配这个方位?

我用SensorManager.getOrientation(rotationMatrix,vals)函数计算方位角,并在方位角上加上全球定位系统的斜度,以得到真正向北的设备航向。

EN

回答 2

Stack Overflow用户

发布于 2015-05-07 06:51:59

这就是我所做的,您可以从这段代码中引用。

onSensorChanged

代码语言:javascript
复制
@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);
                }
            }
        }

计算轴承组件

代码语言:javascript
复制
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);
}

按方向在中旋转图像

代码语言:javascript
复制
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);
}
票数 0
EN

Stack Overflow用户

发布于 2015-05-07 14:38:17

是的,方位是从正北顺时针方向测量(并传递)的。一些人将其描述为北纬东侧的程度。范围是0- 359.99999。北纬0度。

2)注意东侧的数学角度为0°,逆时针方向增大。取决于代码,你必须在地理角度和数学角度之间进行转换。

进一步解释2):如果你看一张地图,那么北是向上,东是对的,这对应于我们在学校里一直使用的2d笛卡儿坐标系:

x,y空间:

在这个空间中,正x是向右的,在大多数地图上是东,向上是正y,或者是在地图上是北,负是西和南。

当将经度坐标转换为笛卡尔x,y时,为了使用简单的学校数学,如角度计算、距离等,你必须考虑所有的数学运算都是基于笛卡尔x,y世界的。在那个世界里,0°是正x轴(地图上的东)。+90°(数学角)为方向。+90向东为x向。因此,匹配角逆时针方向上升,指南针上升(地理角度)顺时针方向上升。

在这些狼人之间转换的时候,你必须考虑到这一点。

然而,对于一些应用程序来说,你不需要在球面和笛卡尔世界之间进行转换,但是当使用加速度和陀螺传感器时,也许你必须这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30093058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档