【发布时间】:2016-11-16 18:27:08
【问题描述】:
我正在尝试对我的应用程序进行编程,以便我的箭头 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 面向我从某个位置获得的坐标。
【问题讨论】:
-
阅读stackoverflow.com/questions/4308262/…。这就是您正在寻找的答案。
标签: java android geolocation location