如何在电报机器人中显示附近的地方?

How to show nearing place in telegram bot?

我在电报中创建了用于显示餐厅附近的机器人我的机器人必须按下第一个按钮才能插入地理坐标餐厅,我的服务器接收纬度和经度并保存它我创建了第一个按钮并且做得很好 但我无法创建第二个按钮来显示附近的餐厅这是我的代码 请帮我 谢谢

<?php
//$json=file_get_contents('php://input');
$update = json_decode(file_get_contents('php://input'));

//main input
$message    = $update->message->text;
$chatid     = $update->message->chat->id;
$last_name  = $update->message->from->last_name;
$first_name = $update->message->from->first_name;
$usernameid = $update->message->from->username;
$latitude   = $update->message->location->latitude;
$longitude  = $update->message->location->longitude;

$text1 = "insert location";
$text2 = "show near restaurant";

$token = '';

$servername = "localhost";
$dbname     = "";
$username   = "";
$password   = "";

//$rep=json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&text=".urldecode($json)));

$reply_markup = json_encode(["keyboard"        =>
                                 [
                                     [["text" => $text1, "request_location" => true]],
                                     //[["text"=>$text1]],
                                     [["text" => $text2]],

                                 ],
                             "resize_keyboard" => true]);

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
mysqli_query($conn, 'set names "utf8"');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: ".$conn->connect_error);
}
echo "Connected successfully";

date_default_timezone_set("Asia/Tehran");
$time = date("h:i:sa");

$date = date("Y/m/d");

if ($message == "/start") {

    $starttxt = "hello".$first_name." ".$last_name."how are you?"."✌️✌️✌️";
    $rep      = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode($starttxt)));

    $sql    = "INSERT INTO user_info (date,time,T_id,T_firstname,T_lastname,T_username) VALUES ('$date','$time','$chatid','$first_name','$last_name','$usernameid')";
    $result = $conn->query($sql);
}

if ($longitude != null) {

    $rep = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode("long is: ".$longitude." lat is: ".$latitude)));

    $sql    = "INSERT INTO insert_location (T_id,T_username,date,time,latitude,longitude) VALUES ('$chatid','$usernameid','$date','$time','$latitude','$longitude')";
    $result = $conn->query($sql);
}

if ($message == "show near restaurant") {

    $rep = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode($starttxt)));

    $sql = SELECT id, (3959 * acos(cos(radians(37)) * cos(radians(latitude)) * cos(radians(longitude) - radians(-122)) + sin(radians(37)) * sin(radians(latitude)))) AS distance FROM insert_location HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

    $result = $conn->query($sql);
}

?>

当用户点击第一个按钮时 mysql 并且此图像形成

你是说 sendVenue 吗?

顺便说一句,我建议使用/setinlinegeo with Venue Result,它可以让用户从最多50个结果中进行选择。

我在 google 地图 api v_3 中找到了这个问题的答案,以显示接近地点

SELECT id, latitude, longitude, ( 6371 * acos ( cos ( radians($latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians($longitude) ) + sin ( radians($latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM insert_location HAVING distance < 3;

6371 公里