如何在android中从北获取任何地理位置的角度?

发布于 2024-12-27 17:06:03 字数 1719 浏览 1 评论 0原文

在我的应用程序中,我想计算特定位置(给出纬度和经度)与北面的角度。有没有办法计算这个。实际上我已经找到了手机的方向,但我想获取位置角度来自北方。这是我的代码。请提出任何相关的解决方案。谢谢

   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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2025-01-03 17:06:03

根据“从北边的位置角度”的含义,有几种可能的解决方案。其中之一是:

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;

Depending on what you mean by "angle of location from the north" there are several possible solutions. One is this:

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];

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)

final float bearing = 0.0f;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文