added getPlace for reverse geocoding

This commit is contained in:
mmacierzanka committed 2021-10-03 22:44:46 +02:00
1 parent e027ab3cb0
commit 9da35b52ad
1 file changed
+8
+8
View File
@@ -0,0 +1,8 @@
import axios from "axios";
export const getPlace = async (pos) => {
if (!Array.isArray(pos) || isNaN(pos[0]) || isNaN(pos[1])) throw new TypeError("Incorrect argument type");
const rq = await axios.get(`https://nominatim.openstreetmap.org/reverse?lat=${pos[1]}&lon=${pos[0]}&format=json&polygon_geojson=1&addressdetails=1`);
if (rq.status !== 200) throw new Error(`Request failed with status code ${rq.status}: ${rq.statusText}`);
return rq.data.address;
};