A
A
Andrey2016-07-21 18:21:19
PHP
Andrey, 2016-07-21 18:21:19

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

3 answer(s)
Андрей, 2016-07-21
@AndreyMyagkov

Нашел решение:
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*/

W
webdeveloper48, 2016-07-21
@webdeveloper48

наймите разработчика,или вы ожидаете что вам напишут рабочий скрипт здесь?

Михаил Румянцев, 2016-07-21
@MGames

формула для расчета расcтояний

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question