sab*_*nke 5 java android location geolocation
我正在尝试编程我的应用程序,所以我的箭头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);
Run Code Online (Sandbox Code Playgroud)
这是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;
}
Run Code Online (Sandbox Code Playgroud)
有没有比我更好的方法呢?我不知道如何让ImageView面向我从一个位置给出的坐标.
小智 1
首先,我不确定为什么你想要图像视图旋转到某个角度。但如果您认为可以用标记替换图像视图,那么就这样做。
在这种情况下使用标记有很多优点
易于获取和设置旋转
你的旋转将会非常顺利
其次,使用该函数获取角度
toAngle = 起始位置.bearingTo(结束位置);
| 归档时间: |
|
| 查看次数: |
202 次 |
| 最近记录: |