Archived
added getPlace for reverse geocoding
This commit is contained in:
1 parent
e027ab3cb0
commit
9da35b52ad
1 file changed
+8
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user