diff --git a/functions/get_img_map.py b/functions/get_img_map.py index 2bf854e..3c44d56 100644 --- a/functions/get_img_map.py +++ b/functions/get_img_map.py @@ -1,52 +1,21 @@ -import sys from io import BytesIO -from get_a_useless_value import get_a_useless_value import requests from PIL import Image -# Пусть наше приложение предполагает запуск: -# python search.py Москва, ул. Ак. Королева, 12 -# Тогда запрос к геокодеру формируется следующим образом: -toponym_to_find = " ".join(sys.argv[1:]) +api_server = "http://static-maps.yandex.ru/1.x/" -geocoder_api_server = "http://geocode-maps.yandex.ru/1.x/" +lon = "37.530887" +lat = "55.703118" +delta = "0.002" -geocoder_params = { - "apikey": "40d1649f-0493-4b70-98ba-98533de7710b", - "geocode": toponym_to_find, - "format": "json"} - -response = requests.get(geocoder_api_server, params=geocoder_params) - -if not response: - # обработка ошибочной ситуации - pass - -# Преобразуем ответ в json-объект -json_response = response.json() -# Получаем первый топоним из ответа геокодера. -toponym = json_response["response"]["GeoObjectCollection"][ - "featureMember"][0]["GeoObject"] -# Координаты центра топонима: -toponym_coodrinates = toponym["Point"]["pos"] -# Долгота и широта: -vrem = [] -for i in toponym_coodrinates.split(" "): - vrem.append(float(i)) -point = vrem -org_point = "{0},{1}".format(point[0], point[1]) -toponym_longitude, toponym_lattitude = toponym_coodrinates.split(" ") -# Собираем параметры для запроса к StaticMapsAPI: -map_params = { - "ll": ",".join([toponym_longitude, toponym_lattitude]), - "spn": ",".join(get_a_useless_value(toponym["boundedBy"]["Envelope"])), - "l": "map", - "pt": "{0},pm2dgl".format(org_point) +params = { + "ll": ",".join([lon, lat]), + "spn": ",".join([delta, delta]), + "l": "map" } -map_api_server = "http://static-maps.yandex.ru/1.x/" -# ... и выполняем запрос -response = requests.get(map_api_server, params=map_params) -Image.open(BytesIO( - response.content)).show() +def get_img_map(): + response = requests.get(api_server, params=params) + Image.open(BytesIO( + response.content)).save("image.png") diff --git a/main.py b/main.py index 471601d..81b37fc 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,17 @@ from PyQt5.QtWidgets import * from PyQt5.QtGui import QPixmap import sys +from functions.get_img_map import get_img_map class Window(QMainWindow): def __init__(self): super().__init__() - self.acceptDrops() self.setWindowTitle("Image") - self.setGeometry(0, 0, 400, 300) + self.setGeometry(0, 0, 600, 450) self.label = QLabel(self) + get_img_map() self.pixmap = QPixmap('image.png') self.label.setPixmap(self.pixmap) self.label.resize(self.pixmap.width(), self.pixmap.height())