diff --git a/src/main.ts b/src/main.ts index 8bb0c0d..34deebb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -422,9 +422,32 @@ if (process.env.HAZARDS_ENABLED) { const nlat = Number(parseFloat(lat).toFixed(4)); const nlon = Number(parseFloat(lon).toFixed(4)); + const mapMatched = await fetch((process.env.VALHALLA || "https://valhalla1.openstreetmap.de") + "/locate", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + locations: [ + { + lat: nlat, + lon: nlon, + } + ] + }) + }).then(res => res.json()).catch(() => null); + + let mmlat = nlat; + let mmlon = nlon; + + if(mapMatched && Array.isArray(mapMatched) && mapMatched[0] && mapMatched[0].edges && mapMatched[0].edges[0]) { + mmlat = mapMatched[0].edges[0].correlated_lat; + mmlon = mapMatched[0].edges[0].correlated_lon; + } + const hazard = new Hazard(); - hazard.latitude = nlat; - hazard.longitude = nlon; + hazard.latitude = mmlat; + hazard.longitude = mmlon; hazard.type = type; hazard.votes = 1; hazard.user = user;