Tag: 轴承

无论屏幕方向如何,如何获得正确的方位(磁方向)?

无论当前的屏幕方向(横向或纵向),我都希望获得当前的磁性方向。 我找到了这个例子,但它不是独立的方向,对吧? 这对我也没有帮助。 我也读过http://android-developers.blogspot.de/2010/09/one-screen-turn-deserves-another.html 。 这是我目前采用的方法,我不想使用(简称): mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); private SensorEventListener sensorEventListener = new SensorEventListener() { public void onSensorChanged(SensorEvent event) { /* Get measured value */ float current_measured_bearing = (float) event.values[0]; /* Compensate device orientation */ switch (((WindowManager) getSystemService(WINDOW_SERVICE)) .getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: current_measured_bearing = current_measured_bearing + 90f; break; case Surface.ROTATION_180: current_measured_bearing = current_measured_bearing – 180f; break; […]

从一个坐标到另一个坐标

我从http://www.movable-type.co.uk/scripts/latlong.html实施了“方位”公式。 但它似乎非常不准确 – 我怀疑我的实施中有些错误。 你能帮我找到它吗? 我的代码如下: protected static double bearing(double lat1, double lon1, double lat2, double lon2){ double longDiff= lon2-lon1; double y = Math.sin(longDiff)*Math.cos(lat2); double x = Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(longDiff); return Math.toDegrees((Math.atan2(y, x))+360)%360; }