在我的应用程序中,我想计算从北方的具体位置(纬度和长度)的角度。有任何方法来计算这个。实际上我发现把手机的方向,但我想得到从北方的位置角度。这是我的代码。请提出任何相关的解决方案。谢谢
myAzimuth=Math.round(event.values[0]);
myPitch=Math.round(event.values[1]);
myRoll=Math.round(event.values[2]);
Toast.makeText(this, "Value"+myAzimuth, Toast.LENGTH_SHORT).show();
if(myAzimuth<22){
Toast.makeText(this, "North Direction", Toast.LENGTH_SHORT).show();
}
else if (myAzimuth >= 22 && myAzimuth < 67)
Toast.makeText(this, "North East", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 67 && myAzimuth < 112)
Toast.makeText(this, "East Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 112 && myAzimuth < 157)
Toast.makeText(this, "South east Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 157 && myAzimuth < 202)
Toast.makeText(this, "South Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 202 && myAzimuth < 247)
Toast.makeText(this, "South west Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 247 && myAzimuth < 292)
Toast.makeText(this, "west Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 292 && myAzimuth < 337)
Toast.makeText(this, "North west Direction", Toast.LENGTH_SHORT).show();
else if (myAzimuth >= 337)
Toast.makeText(this, "North Direction", Toast.LENGTH_SHORT).show();
答案 0 :(得分:1)
根据“北方位置角”的含义,有几种可能的解决方案。一个是这个:
final float[] results= new float[3];
// The computed distance in meters is stored in results[0].
// If results has length 2 or greater, the initial bearing is stored in results[1].
// If results has length 3 or greater, the final bearing is stored in results[2].
Location.distanceBetween(refLat, refLong, 90.0f, 0.0f, results);
final float bearing = results[1];
您可以从参考位置到北极获得路线轴承。在沿着最短距离航线的路线上,轴承/航向会发生变化。
甚至更好,如Konstantin Pribluda所建议的那样(见下面的评论)
final float bearing = 0.0f;