Получить направление (компас) с двумя точками долготы / широты

Я работаю над «компасом» для мобильного устройства. У меня есть следующие пункты:

point 1 (current location): Latitude = 47.2246, Longitude = 8.8257
point 2 (target  location): Latitude = 50.9246, Longitude = 10.2257

Также у меня есть следующая информация (с моего телефона Android):

The compass-direction in degree, wich bears to the north. 
For example, when I direct my phone to north, I get 0°

Как я могу создать стрелку, похожую на компас, которая показывает мне направление к точке?

Является ли есть ли математическая проблема для этого?

спасибо!

РЕДАКТИРОВАТЬ: Хорошо, я нашел решение, оно выглядит так:

/**
 * 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;
}

У меня это отлично работает!

19
задан eav 14 December 2011 в 16:25
поделиться