所以我试图制作一个应用程序来跟踪手机通过指南针指向的方向,一旦在屏幕上按下一个按钮,它就会显示它指向的位置的度数。到目前为止,我了解指南针是如何创建的,但找不到与北方相关的指向方向的值。这是我到目前为止所拥有的。
public class compass extends Activity implements OnClickListener, SensorEventListener{
private final SensorManager DirPoint;
float var;
TextView theNumber;
Button DirectionIn;
public compass(){
DirPoint = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onSensorChanged(SensorEvent event) {}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theNumber = (textView) findViewById(R.id.output);
DirectionIn =(Button) findViewById(R.Id.Buton);
DirectionIn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//gets direction of phone compass
// ((TextView)findViewById(R.id.output)).setText(var);
}
}
}
}
任何帮助都会受到欢迎,或者如果我朝着正确的方向前进,甚至会很好。