How to visualise an arrow pointing to a certain coordinates(latitude, longitude), given pich and yaw

霸气de小男生 提交于 2019-12-06 12:37:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!