From db67aa9f61c742afb419a197d871aec8a52a667e Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Thu, 23 Oct 2025 11:08:10 +0000 Subject: [PATCH] Add automatic geocoding for site addresses to improve GPS accuracy Integrate Nominatim API via a new backend endpoint and frontend button to automatically convert site addresses into GPS coordinates, enhancing accuracy for the mobile planning map. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/TFybNy5 --- replit.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/replit.md b/replit.md index dc8928c..e7cd54f 100644 --- a/replit.md +++ b/replit.md @@ -54,6 +54,22 @@ The database includes tables for `users`, `guards`, `certifications`, `sites`, ` To prevent timezone-related bugs, especially when assigning shifts, dates should always be constructed from components (`new Date(year, month-1, day)`) and never parsed from ISO strings directly using `parseISO()` or `new Date(string ISO)`. Date validation should use regex instead of `parseISO()`. ## Recent Changes (October 2025) +### Automatic Geocoding Integration (October 23, 2025) +- **Issue**: Users had to manually find and enter GPS coordinates for sites, which was time-consuming and error-prone +- **Solution**: + - **Backend (`server/routes.ts`)**: + - Created POST `/api/geocode` endpoint integrating Nominatim API (OpenStreetMap) + - Implemented in-memory rate limiter enforcing 1 request/second to comply with Nominatim usage policy + - Added compliant User-Agent header: "VigilanzaTurni/1.0 (Security Shift Management System; contact: support@vigilanzaturni.it)" + - Returns latitude, longitude, displayName, and full address object + - **Frontend (`client/src/pages/sites.tsx`)**: + - Added "📍 Trova Coordinate" button in both create and edit site dialogs + - Button auto-populates latitude/longitude fields from address + - Disabled state when address missing or geocoding in progress + - Toast notifications for success (with found address) and error handling + - Dedicated section with bg-muted/50 highlighting for GPS coordinates +- **Impact**: Users can now automatically geocode site addresses with a single click, ensuring accurate GPS positioning for Planning Mobile map without manual coordinate lookup + ### Planning Mobile - Leaflet Map Integration (October 23, 2025) - **Issue**: Planning Mobile page had errors in backend endpoints and lacked interactive map functionality - **Solution**: @@ -88,4 +104,5 @@ To prevent timezone-related bugs, especially when assigning shifts, dates should - **TanStack Query**: For data fetching and state management. - **Wouter**: For client-side routing. - **date-fns**: For date manipulation and formatting. -- **Leaflet**: Interactive map library with react-leaflet bindings and OpenStreetMap tiles (free). \ No newline at end of file +- **Leaflet**: Interactive map library with react-leaflet bindings and OpenStreetMap tiles (free). +- **Nominatim**: OpenStreetMap geocoding API for automatic address-to-coordinates conversion (free, rate limited to 1 req/sec). \ No newline at end of file