Answer the question
In order to leave comments, you need to log in
How can Bitrix calculate the cost of delivery depending on the distance from the online store?
There is an online food delivery store, when placing an order, the buyer indicates the address and area where the goods need to be delivered. It is necessary to make it possible that the cost of delivery depends on the distance from the store to the buyer and is calculated when the buyer enters his data in the address field.
How can Bitrix calculate the cost of delivery depending on the distance from the online store?
Perhaps there is a module that allows you to calculate the cost of delivery depending on the distance. For example, in the administrative section, the address of the online store is indicated, and then the distances in kilometers and the cost of delivery depending on the distance are indicated. If up to 1 km then 50 rubles, if from 1 km to 5 km - 100 and more 5 - 250 km rubles.
Answer the question
In order to leave comments, you need to log in
The option is more accurate, along the
Yandex.Maps API
route The
second option is along the radius:
// Радиус земли
define('EARTH_RADIUS', 6372795);
/*
* Расстояние между двумя точками
* $φA, $λA - широта, долгота 1-й точки,
* $φB, $λB - широта, долгота 2-й точки
* Написано по мотивам http://gis-lab.info/qa/great-circles.html
* Михаил Кобзарев <[email protected]>
*
*/
function calculateTheDistance ($φA, $λA, $φB, $λB) {
// перевести координаты в радианы
$lat1 = $φA * M_PI / 180;
$lat2 = $φB * M_PI / 180;
$long1 = $λA * M_PI / 180;
$long2 = $λB * M_PI / 180;
// косинусы и синусы широт и разницы долгот
$cl1 = cos($lat1);
$cl2 = cos($lat2);
$sl1 = sin($lat1);
$sl2 = sin($lat2);
$delta = $long2 - $long1;
$cdelta = cos($delta);
$sdelta = sin($delta);
// вычисления длины большого круга
$y = sqrt(pow($cl2 * $sdelta, 2) + pow($cl1 * $sl2 - $sl1 * $cl2 * $cdelta, 2));
$x = $sl1 * $sl2 + $cl1 * $cl2 * $cdelta;
//
$ad = atan2($y, $x);
$dist = $ad * EARTH_RADIUS;
return $dist;
}
$lat1 = 77.1539;
$long1 = -139.398;
$lat2 = -77.1804;
$long2 = -139.55;
echo calculateTheDistance($lat1, $long1, $lat2, $long2) . " метров";
// Вернет "17166029 метров"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question