feat(geocoding): implement address search and reverse geocoding APIs

This commit is contained in:
gabdevele
2026-06-15 14:43:00 +02:00 Unverified
parent 645e6367e9
commit 486cded844
4 changed files with 478 additions and 33 deletions
+20
View File
@@ -0,0 +1,20 @@
import { createError, getQuery } from 'h3'
import { searchAddresses } from '../../utils/geocoding'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const rawText = typeof query.q === 'string' ? query.q.trim() : ''
const rawLimit = typeof query.limit === 'string' ? Number.parseInt(query.limit, 10) : 5
const limit = Number.isFinite(rawLimit) ? Math.min(Math.max(rawLimit, 1), 8) : 5
if (rawText.length < 3) {
throw createError({
statusCode: 400,
statusMessage: 'Query too short'
})
}
const suggestions = await searchAddresses(rawText, limit)
return { suggestions }
})