我正在尝试对我的应用程序进行编程,以便我的箭头 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 那么就这样做吧。
在这种情况下使用标记有很多优点
易于获取和设置旋转
你的轮换会很顺利
其次,使用这个函数来获取角度
toAngle = startingLocation.bearingTo(endingLocation);
关于java - 旋转 ImageView 以面对给定的纬度和经度位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364004/