Answer the question
In order to leave comments, you need to log in
How, knowing the coordinates of the site visitor and the coordinates of the offices, show the nearest office to him?
We have geographic coordinates of the site visitor, coordinates of offices. It is necessary to determine the office closest to the visitor. Need a formula for calculating distances by coordinates, preferably in JS
Answer the question
In order to leave comments, you need to log in
Нашел решение:
var radLat1 = 55 * (Math.PI/180);
var radLon1 = 37 * (Math.PI/180);
var radLat2 = 59 * (Math.PI/180);
var radLon2 = 30 * (Math.PI/180);
var earthRadius = 6372.795;
var radLonDif = radLon2 - radLon1;
var atan2top = Math.sqrt( Math.pow( Math.cos(radLat2) * Math.sin(radLonDif), 2 ) + Math.pow( Math.cos(radLat1)*Math.sin(radLat2) - Math.sin(radLat1) * Math.cos(radLat2) * Math.cos(radLonDif), 2 ) );
var atan2bottom = Math.sin(radLat1)*Math.sin(radLat2)+Math.cos(radLat1)*Math.cos(radLat2)*Math.cos(radLonDif);
var deltaAngle = Math.atan2(atan2top, atan2bottom);
console.log(earthRadius*deltaAngle); /* 614*/
наймите разработчика,или вы ожидаете что вам напишут рабочий скрипт здесь?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question