diff --git a/functions/get_img_map.py b/functions/get_img_map.py index 14de117..5890bcc 100644 --- a/functions/get_img_map.py +++ b/functions/get_img_map.py @@ -3,10 +3,11 @@ import requests from PIL import Image -def get_img_map(delta: float, cords: tuple, variant_map: str) -> None: +def get_img_map(delta: float, cords: tuple, variant_map: str, org_point: str) -> None: """ Функция обращается к api yandex и создаёт картинку карты по переданным данным + :param org_point: str - координаты организации, куда надо точку поставить :param delta: float - разрешение карты :param cords: tuple - 2 координаты точки :param variant_map: str - вариант карты @@ -15,7 +16,8 @@ def get_img_map(delta: float, cords: tuple, variant_map: str) -> None: params = { "ll": ",".join([str(cords[0]), str(cords[1])]), "spn": ",".join([str(delta), str(delta)]), - "l": variant_map + "l": variant_map, + "pt": "{0},pm2dgl".format(org_point) } response = requests.get("http://static-maps.yandex.ru/1.x/", params=params) # print(response.text) diff --git a/functions/search_organization_pos.py b/functions/search_organization_pos.py new file mode 100644 index 0000000..839d16c --- /dev/null +++ b/functions/search_organization_pos.py @@ -0,0 +1,14 @@ +import requests + + +def search_organization_pos(search_text: str) -> tuple: + geocoder_api_server = "http://geocode-maps.yandex.ru/1.x/" + geocoder_params = { + "apikey": "40d1649f-0493-4b70-98ba-98533de7710b", + "geocode": search_text, + "format": "json"} + response = requests.get(geocoder_api_server, params=geocoder_params) + toponym = response.json()["response"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"] + point = [float(i) for i in toponym["Point"]["pos"].split(" ")] + toponym_longitude, toponym_lattitude = toponym["Point"]["pos"].split(" ") + return "{0},{1}".format(point[0], point[1]), toponym_longitude, toponym_lattitude diff --git a/image.png b/image.png index 68a54ea..b62c7cb 100644 Binary files a/image.png and b/image.png differ diff --git a/main.py b/main.py index b95dc2e..5439cbc 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import sys from PyQt5 import uic from PyQt5 import QtCore from functions.get_img_map import get_img_map +from functions.search_organization_pos import search_organization_pos class Window(QMainWindow): @@ -17,12 +18,14 @@ class Window(QMainWindow): self.lon = 37.530887 self.lat = 55.703118 self.variant_map = "map" + self.org_point = "0.0,0.0" self.update() - self.button_group = QButtonGroup() + self.button_group = QButtonGroup(None) self.button_group.addButton(self.map) self.button_group.addButton(self.sat) self.button_group.addButton(self.skl) self.button_group.buttonClicked.connect(self.push_button) + self.find.clicked.connect(self.search_organization) def keyPressEvent(self, event): try: @@ -49,7 +52,7 @@ class Window(QMainWindow): print(e) def update(self): - get_img_map(self.delta, (self.lon, self.lat), self.variant_map) + get_img_map(self.delta, (self.lon, self.lat), self.variant_map, self.org_point) self.pixmap = QPixmap('image.png') self.label.setPixmap(self.pixmap) self.label.resize(self.pixmap.width(), self.pixmap.height()) @@ -62,6 +65,11 @@ class Window(QMainWindow): self.variant_map = button.text() self.update() + def search_organization(self): + # Москва, ул. Ак. Королева, 12 + self.org_point, self.lon, self.lat = search_organization_pos(self.plainTextEdit.toPlainText()) + self.update() + App = QApplication(sys.argv) window = Window() diff --git a/window.ui b/window.ui new file mode 100644 index 0000000..bcbe64d --- /dev/null +++ b/window.ui @@ -0,0 +1,107 @@ + + + MainWindow + + + + 0 + 0 + 800 + 550 + + + + MainWindow + + + + + + 0 + 70 + 600 + 450 + + + + + + + + + + 610 + 0 + 191 + 71 + + + + Искать + + + + + + 610 + 70 + 114 + 25 + + + + map + + + + + + 610 + 100 + 114 + 25 + + + + sat + + + + + + 610 + 130 + 114 + 25 + + + + skl + + + + + + 0 + 0 + 611 + 70 + + + + + + + + 0 + 0 + 800 + 29 + + + + + + + +