From d21b41326753049797b5bdf3f64819c6ba7b06c7 Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Fri, 22 Apr 2022 01:48:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D0=B5=D1=80=D1=81=20=D0=B3=D0=B5=D0=BE=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D0=BD=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wheretogo/static/maps/js/map.js | 43 ++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/wheretogo/static/maps/js/map.js b/wheretogo/static/maps/js/map.js index 339f9a2..d3e17a4 100644 --- a/wheretogo/static/maps/js/map.js +++ b/wheretogo/static/maps/js/map.js @@ -27,20 +27,39 @@ map.on("moveend", renderFacilities); map.on("click", function (e) { const { lat, lng } = e.latlng; - const api = `https://nominatim.openstreetmap.org/reverse.php?lat=${lat}&lon=${lng}&zoom=18&format=jsonv2`; + const get_addr_api = `https://nominatim.openstreetmap.org/reverse.php?lat=${lat}&lon=${lng}&zoom=18&format=jsonv2`; - fetchAddressData(api).then((data) => { + + fetchAddressData(get_addr_api).then((data) => { const { country, state, city, house_number, road } = data.address; console.log(country + ', ' + state + ', ' + city + ', ' + road + ', ' + house_number); - }); -}); -async function fetchAddressData(url) { - try { - const response = await fetch(url); - const data = await response.json(); - return data; - } catch (err) { - console.error(err); + const get_long_api = `https://nominatim.openstreetmap.org/search.php?q=${road + ' ' + house_number + ' ' + city}&format=jsonv2&limit=1&addressdetails=1`; + + fetchLatLonData(get_long_api).then((data) => { + const { country, state, city, house_number, road } = data[0].address; + console.log(country + ', ' + state + ', ' + city + ', ' + road + ', ' + house_number); + }); + + }); + + async function fetchAddressData(url) { + try { + const response = await fetch(url); + const data = await response.json(); + return data; + } catch (err) { + console.error(err); + } + }; + + async function fetchLatLonData(url) { + try { + const response = await fetch(url); + const data = await response.json(); + return data; + } catch (err) { + console.error(err); + } } -} +})