(function () {
    'use strict';

    angular
        .module('contestacaoApp')
        .factory('gpsFactory', gpsFactory);

    gpsFactory.$inject = [];

    function gpsFactory() {
        function degToRad(degrees) {
            return (degrees / 180.0) * Math.PI;
        }

        function leiCosenos(pt1, pt2) {
            if (pt1 == null || pt2 == null)
                return Number.NaN;

            let lat1 = degToRad(pt1[0]);
            let lon1 = degToRad(pt1[1]);

            let lat2 = degToRad(pt2[0]);
            let lon2 = degToRad(pt2[1]);

            return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * 6371 * 1000;
        }

        return {
            leiCosenos: leiCosenos
        }
    }
})();
