Sto lavorando su una "bussola" per un dispositivo mobile. Ho i seguenti punti:Ottieni direzione (bussola) con due punti di latitudine/longitudine
point 1 (current location): Latitude = 47.2246, Longitude = 8.8257
point 2 (target location): Latitude = 50.9246, Longitude = 10.2257
anche io ho le seguenti informazioni (dal mio Android-phone): mi
The compass-direction in degree, wich bears to the north.
For example, when I direct my phone to north, I get 0°
Come posso creare una freccia wich "compasso" mostra la direzione al punto?
C'è un problema matematico per questo?
grazie!
EDIT: Ok ho trovato una soluzione, sembra che questo:
/**
* Params: lat1, long1 => Latitude and Longitude of current point
* lat2, long2 => Latitude and Longitude of target point
*
* headX => x-Value of built-in phone-compass
*
* Returns the degree of a direction from current point to target point
*
*/
function getDegrees(lat1, long1, lat2, long2, headX) {
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
lat1 = toRad(lat1);
lat2 = toRad(lat2);
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = toDeg(Math.atan2(y, x));
// fix negative degrees
if(brng<0) {
brng=360-Math.abs(brng);
}
return brng - headX;
}
questo funziona per me grande!
Non pubblicare la soluzione su cui anche tu non sei chiaro. – Sameer
@Sameer qual è il tuo problema con la soluzione? Se nobodoy ne pubblica uno, posso essere io. È solo per riferimento, se qualcun altro ha bisogno. Ottenere un down-vote per quella "ragione". Non capisco – eav
@eav Che aspetto ha la funzione toRad creata? – gohnjanotis