mirror of
https://github.com/Llloooggg/WhereToGo.git
synced 2026-03-06 04:36:22 +03:00
Базовый реверс геокодинга
This commit is contained in:
@@ -27,20 +27,39 @@ map.on("moveend", renderFacilities);
|
|||||||
map.on("click", function (e) {
|
map.on("click", function (e) {
|
||||||
const { lat, lng } = e.latlng;
|
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;
|
const { country, state, city, house_number, road } = data.address;
|
||||||
console.log(country + ', ' + state + ', ' + city + ', ' + road + ', ' + house_number);
|
console.log(country + ', ' + state + ', ' + city + ', ' + road + ', ' + house_number);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
async function fetchAddressData(url) {
|
const get_long_api = `https://nominatim.openstreetmap.org/search.php?q=${road + ' ' + house_number + ' ' + city}&format=jsonv2&limit=1&addressdetails=1`;
|
||||||
try {
|
|
||||||
const response = await fetch(url);
|
fetchLatLonData(get_long_api).then((data) => {
|
||||||
const data = await response.json();
|
const { country, state, city, house_number, road } = data[0].address;
|
||||||
return data;
|
console.log(country + ', ' + state + ', ' + city + ', ' + road + ', ' + house_number);
|
||||||
} catch (err) {
|
});
|
||||||
console.error(err);
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user