android 没有指南针,Android指南针指向我的位置,而不是北部

我正在开发罗盘应用程序,我希望指南针指向特定的纬度经度位置,而不是通常的北方.我发现有一些

questions与我的问题有关,但我没有办法让他们为我工作.这是我的代码:

public class MainActivity extends AppCompatActivity implements SensorEventListener {

private ImageView image;

private float currentDegree = 0f;

private SensorManager mSensorManager;

private TextView tvHeading;

private Location location = new Location("A");

private Location target = new Location("B");

private LocationManager locationManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

image = (ImageView) findViewById(R.id.imageViewCompass);

tvHeading = (TextView) findViewById(R.id.tvHeading);

mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

location.setLatitude(54.903535);

location.setLongitude(23.979342);

target.setLatitude(54.904618);

target.setLongitude(23.978782);

}

@Override

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),

SensorManager.SENSOR_DELAY_GAME);

}

@Override

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this); // to stop the listener and save battery

}

@Override

public void onSensorChanged(SensorEvent event) {

float degree = Math.round(event.values[0]);

tvHeading.setText("Heading: " + Float.toString(degree) + " degrees");

RotateAnimation ra = new RotateAnimation(

currentDegree,

-degree,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF,

0.5f);

ra.setDuration(210);

ra.setFillAfter(true);

image.startAnimation(ra);

currentDegree = -degree;

}

@Override

public void onAccuracyChanged(Sensor sensor, int accuracy) {

// not in use

}

}

目前我的指针只显示在北方,而不是我的编码目标位置.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值