Answer the question
In order to leave comments, you need to log in
How to select points specified in geolocation at a certain radius in a telegram bot?
There are set points in the telegram bot (during registration, the client indicates the address of the service), the user sends his location and selects the search radius, the bot must show the points corresponding to the specified radius.
I've searched everywhere, but I can't find the answer, can someone tell me? php language
Answer the question
In order to leave comments, you need to log in
Depending on the number of points. If you have few of them there, and there are no problems to calculate, then use the distance calculation function. For example, I have a function for POINT values, rewrite yourself under lat long.
And further through foreach you check necessary conditions.
static function distance($point1, $point2, $unit = 2 ) {
if (!$point2) return null;
if (!$point1) return null;
$point1 = explode(',', $point1);
$lon1 = $point1[0];
$lat1 = $point1[1];
$point2 = explode(',', $point2);
$lon2 = $point2[0];
$lat2 = $point2[1];
if ($lon1 == 0 || $lon2 == 0) {
return null;
}
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
switch ($unit) {
case(self::UNIT_KM) :
$out = $miles * 1.609344;
break;
case(self::UNIT_MI) :
$out = $miles;
break;
case(self::UNIT_NA) :
$out = $miles * 0.8684;
break;
}
return $out;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question