Android GPS方位在哪个刻度上
在哪个刻度上执行Android GPS方位在哪个刻度上,android,gps,android-sensors,magnetometer,Android,Gps,Android Sensors,Magnetometer,在哪个刻度上执行location.getBearing()返回角度,是从真北以东的0到360度,还是其他刻度 如果我的手机与运动方向平行,我的手机朝向正北是否需要与此方向一致 我使用SensorManager.getOrientation(rotationMatrix,VAL)函数计算方位角,并将GPS偏角添加到该函数中,以获得设备朝向正北的方向。我所做的工作可以从该代码中参考 on传感器更改 @Override public void onSensorChanged(Sens
location.getBearing()
返回角度,是从真北以东的0到360度,还是其他刻度
我使用SensorManager.getOrientation(rotationMatrix,VAL)函数计算方位角,并将GPS偏角添加到该函数中,以获得设备朝向正北的方向。我所做的工作可以从该代码中参考 on传感器更改
@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);
}
}
}
计算轴承comapss
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);
}
是的,从正北顺时针方向测量(和交付)轴承的度数。
有人将其描述为北偏东度。
范围为0-359.99999。
所以北纬0度
(二)
注意,数学角度在东方为0°,逆时针增加。
根据代码,您必须在地理角度到数学角度之间进行转换
对第2条的进一步解释:
如果你在地图上看,那么北方在上面,东方在右边,这对应于我们在学校经常使用的二维笛卡尔坐标系:
x,y空间:
在这个空间中,正的x是向右的,在大多数地图上是向东的,正的y是向上的,或是在地图上是向北的,负的是向西和向南的。
将纬度经度坐标按顺序转换为笛卡尔x,y时
使用更简单的学校数学,如角度计算、距离等。
然后,你必须考虑所有的数学运算都是基于笛卡尔X,Y世界。在这个世界上,0°是正x轴方向(地图上的东方)+90°(数学角度)方向为y轴。而+90地理方位位于x轴方向的东部。
因此,地球自转角逆时针上升,罗盘上升(=地球自转角)顺时针上升
当这些狼之间转换时,你必须考虑到。
然而,对于某些应用程序,您不必在球面和笛卡尔坐标世界之间进行转换,但在使用加速度和陀螺传感器时,您可能必须进行转换。以下是您需要的内容,这对我帮助很大@kishorejethava,但我仍然感到困惑…@kishorejethava,因为设备航向和gps方位在某些情况下不匹配。@AlecWien是的,我理解了第一部分,方位是从正北顺时针方向0到359.9999,但在第二部分,我仍然感到困惑…请详细说明。我已经尝试过了,但我的问题是仍然没有回答/@ParasDhawan查看此视频了解真实方位您可以搜索更多视频
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);
}