2012-03-05 67 views

Respuesta

4

Tomado de this anterior SO mensaje:

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

¿Qué son 'M_PI' y' atan2f'? – FaCoffee

+1

@ CF84: Eche un vistazo al enlace [this] (http://stackoverflow.com/questions/15231466/whats-the-difference-between-pi-and-m-pi-in-objc) para 'M_PI' . Para 'atan2f', eche un vistazo [aquí] (http://stackoverflow.com/questions/7418353/angle-between-two-lines-is-wrong). – npinti

5

supongo que quiere decir que el rodamiento y no el ángulo entre las ubicaciones: Si (Lat1, LONG1) se almacena en un objeto Locationloc1 y (Lat2, long2) se almacena en loc2 se obtiene el cojinete de LOC1 a Loc2 así:

float bearing = loc1.bearingTo(loc2); 

el resultado se expresa en grados al este del norte verdadero y su cojinete inicial (lo cual es importante si LOC1 y LOC2 son muy ap arte el uno del otro).

Hay algunos otros métodos útiles en la clase Location, ver aquí para más detalles: http://developer.android.com/reference/android/location/Location.html

EDIT: Asumí Android para la respuesta, pero sí, las etiquetas no implican que ...

+2

Eso está bien si está en Android, pero las etiquetas no dicen que lo es. – JeremyP

Cuestiones relacionadas