Commit 89b0b81b authored by Steven's avatar Steven

fix(web): add required headers for Nominatim reverse geocoding API

Nominatim's usage policy requires a User-Agent header to identify the application. Added User-Agent and Accept headers to the reverse geocoding fetch request, and improved error handling to check HTTP response status.

Fixes #5222

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 4c1d1c70
......@@ -78,8 +78,18 @@ const InsertMenu = observer((props: Props) => {
const handlePositionChange = (position: LatLng) => {
location.handlePositionChange(position);
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`)
.then((response) => response.json())
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`, {
headers: {
"User-Agent": "Memos/1.0 (https://github.com/usememos/memos)",
Accept: "application/json",
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
if (data?.display_name) {
location.setPlaceholder(data.display_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment