问题
I would like to know how to visualise an arrow pointing to a certain coordinates(latitude, longitude) while I'm moving around holding my handset.
I'va calculated the pitch and yaw of the desired position. Now I want to know how to keep pointing to this position while moving.
Regards,
回答1:
In general you can calculate the bearing angle (the angle between your local meridian and the great circle connecting your current position and the target position measured from the north direction) using this formula:
double y = Math.sin(long2-long1)*Math.cos(lat2);
double x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(long2-long1);
double bearing = Math.atan2(y, x);
Note that lat1
, long1
, lat2
, long2
and bearing
are all in radians. The formula assumes perfectly spherical Earth. See also this page.
For more accurate results based on WSG84 you can use android.location.Location's bearingTo() method.
Then you can either use compass and draw the arrow at the computed bearing angle to the north-south line or you can assume the north to lie at the top of your phone's screen. The second approach makes a lot of sense if you display a map since most people are accustomed to having north at the top.
来源:https://stackoverflow.com/questions/8700344/how-to-visualise-an-arrow-pointing-to-a-certain-coordinateslatitude-longitude