function isLatitude(latitude) { return ( latitude != undefined && isFinite(latitude) && Math.abs(latitude) <= 90 ); } function isLongitude(longitude) { return ( longitude != undefined && isFinite(longitude) && Math.abs(longitude) <= 180 ); } function checkValidCoordinations(coordinations) { if (isLatitude(coordinations[0]) && isLongitude(coordinations[1])) { return true; } else { setError(coordinations); } } function setError(coordinations) { alert("Coordinations " + coordinations + " are not valid."); } function countAzimuth(lat1, lng1, lat2, lng2) { // Convert to radians const lat1Rad = (lat1 * Math.PI) / 180; const lon1Rad = (lng1 * Math.PI) / 180; const lat2Rad = (lat2 * Math.PI) / 180; const lon2Rad = (lng2 * Math.PI) / 180; // Azimuth Calculation const y = Math.sin(lon2Rad - lon1Rad) * Math.cos(lat2Rad); const x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(lon2Rad - lon1Rad); // Convert to degrees let angle = (Math.atan2(y, x) * 180) / Math.PI; // Normalize to 0-360 degrees angle = Math.round(((angle + 360) % 360) - 90); return angle; }