如何在android中从北获取任何地理位置的角度?
在我的应用程序中,我想计算特定位置(给出纬度和经度)与北面的角度。有没有办法计算这个。实际上我已经找到了手机的方向,但我想获取位置角度来自北方。这是我的代码。请提出任何相关的解决方案。谢谢
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();
In my app i want to calculate the angle of the specific location(lat and longs are given) from the north.is there any way to calculate this.Actually i have find put the direction of the phone but i want to get angle of location from north.here is my code.please suggest any related solution.Thankx
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据“从北边的位置角度”的含义,有几种可能的解决方案。其中之一是:
您获得从参考位置到北极的航线方位。当遵循最短距离航向时,方位/航向会发生变化。
或者按照 Konstantin Pribluda 的建议更好(见下面的评论)
Depending on what you mean by "angle of location from the north" there are several possible solutions. One is this:
You get the bearing for a course from your reference location to the north pole. The bearing/heading changes while following the course on a least distance course.
Or even better as suggested by Konstantin Pribluda (see comment below)