I am trying to program my app so my ImageView of an arrow will point at a given android.Location. Right now it doesn't point in the right direction. It is pretty off for some reason. I think it is because I'm not taking into account what direction I am facing correctly.
Here is what I am doing currently:
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);
Here is the GetAngle() function:
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;
}
Is there a better way to do this than how I am? I have no idea how to get the ImageView to face toward the coordinates that I am given from a location.