java - 旋转 ImageView 以面对给定的纬度和经度位置

标签 java android geolocation location

我正在尝试对我的应用程序进行编程,以便我的箭头 ImageView 将指向给定的 android.Location。现在它没有指向正确的方向。由于某种原因,它很糟糕。我认为这是因为我没有考虑到我正确面对的方向。

这是我目前正在做的事情:

float angle = GetAngle(myLocation);
RotateAnimation anim = new RotateAnimation(0.0f, angle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(0);
anim.setDuration(2);
anim.setFillAfter(true);
arrow.startAnimation(anim);

这是 GetAngle() 函数:

float GetAngle(Location myLocation)
{
    float angle = (float) Math.toDegrees(Math.atan2(theirLocation.getLatitude() - myLocation.getLatitude(), theirLocation.getLongitude() - myLocation.getLongitude()));
    if (angle < 0)
        angle += 360;
    return angle;
}

有比我现在更好的方法吗?我不知道如何让 ImageView 面向我从某个位置给出的坐标。

最佳答案

首先,我不确定您为什么要将 ImageView 旋转到某个角度。但是如果你认为你可以用标记替换 imageview 那么就这样做吧。

在这种情况下使用标记有很多优点

  1. 易于获取和设置旋转

  2. 你的轮换会很顺利

其次,使用这个函数来获取角度

toAngle = startingLocation.bearingTo(endingLocation);

关于java - 旋转 ImageView 以面对给定的纬度和经度位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364004/

相关文章:

java - 如何修复我的 .text 字计数器中的 NullPointerException

java - libgdx 上的无限滚动背景

android - 如何在字符串数组中设置文本样式?

android - 默认的 Android Studio 抽屉导航图标

java - 需要 map 验证路径框架的建议

java - 教程上的android错误找不到符号变量activity_display_message

java - 在 Spark 中,是否可以在两个执行者之间共享数据?

java - 有没有办法用一种方法而不是两种方法来做?

c# - 如何用BingMap计算 map 4个角(边)的坐标?

linux - HTML5 地理定位在 Windows 上比在 Linux 上更准确(Firefox、Chrome、[Chromium])