2012-03-05 203 views

回答

4

this以前SO后摘自:

float dy = lat2 - lat1; 
float dx = cosf(M_PI/180*lat1)*(long2 - long1); 
float angle = atan2f(dy, dx); 
+1

什么是'M_PI'和'atan2f'? – FaCoffee 2016-12-15 14:28:42

+1

@ CF84:请查看[M_PI]的[this](http://stackoverflow.com/questions/15231466/whats-the-difference-between-pi-and-m-pi-in-objc)链接。对于'atan2f'请看看[这里](http://stackoverflow.com/questions/7418353/angle-between-two-lines-is-wrong)。 – npinti 2016-12-16 05:42:03

5

我想你指的是轴承,而不是位置之间的角度:如果(LAT1,long1)存储在Location对象loc1和(LAT2, long2)存储在loc2你从LOC1的轴承LOC2这样的:

float bearing = loc1.bearingTo(loc2); 

结果是度东部正北和初始轴承(这是重要的,如果LOC1和LOC2远远AP艺术彼此)。

里有Location类其他一些有用的方法,在这里看到更多的细节:http://developer.android.com/reference/android/location/Location.html

编辑:我认为Android的答案,但肯定的,标签不意味着...

+2

这很好,如果他在Android上,但标签不会说他是。 – JeremyP 2012-03-06 13:54:58