T
T
Tim2452020-08-12 11:42:29
Python
Tim245, 2020-08-12 11:42:29

How can I make the bot send my geolocation?

How can I get the bot to send me my geolocation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Studentka1996, 2020-08-12
@Tim245

Hold on, fixed it. Works perfect. Good luck
5f33bbcda9890140752145.png
To determine the exact address from the coordinates received from the user, use dadata

import dadata
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton  
from telebot import types #для создания клавиатуры   
@bot.message_handler(commands=['start'])
def start_msg(message):
    #Клавиатура Geo, отправка геолакации
    Geo = types.ReplyKeyboardMarkup(True, True)
    button_geo = types.KeyboardButton("Отправить местоположение", request_location=True)
    Geo.add(button_geo) 
    #Создаём объект закрытия кастомной клавиатуры
    Geo_close = types.ReplyKeyboardRemove()
    bot.send_message(message.chat.id, 'Поделитесь местоположением или введите адрес', reply_markup=buttons.Geo ) 
 #------------------------------------Определение адреса юзера-----------------------------------
@bot.message_handler( content_types=["location"])
def location(message):
    if message.location is not None:
        #Получили координаты юзера, после отправки местоположения
        print(message.location)
        print("latitude: %s; longitude: %s" % (message.location.latitude, message.location.longitude))
        #С помощью координат определили точный адрес юзера
        dadata = Dadata(‘ключ, полученный на сайте Dadata')
        full_addres = dadata.geolocate(name="address",lat=message.location.latitude, lon=message.location.longitude)
        bot.send_message(message.chat.id, f'Текущий адрес: {full_addres[0]["value"]}',  reply_markup = buttons.Geo_close )

A
Andrey, 2020-08-12
@anerev

Send him your location)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question