Geoapify Service
core/services/geoapify_service.dart
Overview
Static helper around Geoapify's autocomplete / geocode / reverseGeocode endpoints. Used by the address pickers in checkout, profile, and the seller onboarding wizard. Search uses it for an in-screen 'find a city' affordance.
User Flow
- isConfigured gates every call — falls back to empty results when GEOAPIFY_API_KEY is missing.
- autocomplete: text + optional bias (lat/lon) + limit; returns MapPlaceSuggestion[].
- geocode: text → single best match.
- reverseGeocode: lat/lon → single MapPlaceSuggestion.
Cases & Edge Cases
- Empty/missing API key is a configuration error in .env but returns gracefully (no crash) so debug builds without keys still work.
- Bias parameter format is 'proximity:lon,lat' — Geoapify uses lon,lat (not lat,lon).
- Default 5s timeout — Geoapify is rarely slower but a flaky network surfaces as an empty suggestion list, not an error.
Code References
- lib/src/core/services/geoapify_service.dart:5 // GeoapifyService
- lib/src/core/services/geoapify_service.dart:20 // autocomplete
- lib/src/core/services/geoapify_service.dart:56 // geocode
- lib/src/core/services/geoapify_service.dart:80 // reverseGeocode
API Calls
- GET
https://api.geoapify.com/v1/geocode/autocompleteno statusPlace autocomplete for address fields across search, map picker, checkout, prestation.
RequestQuery: text=:q, limit=:n, format=json, apiKey=:GEOAPIFY_API_KEY, bias?=proximity:<lon>,<lat>
Response{ results: GeoapifyResult[] } → mapped to MapPlaceSuggestion[]lib/src/core/services/geoapify_service.dart:20 // autocompleteauth: API key in query. Bias uses Geoapify's lon,lat ordering. Default 5s timeout — flaky network surfaces as empty list, not error.
- GET
https://api.geoapify.com/v1/geocode/searchno statusForward-geocode a single query string to a place.
RequestQuery: text=:q, limit=1, format=json, apiKey=:GEOAPIFY_API_KEY
Response{ results: [first] } → MapPlaceSuggestion | nulllib/src/core/services/geoapify_service.dart:56 // geocodeauth: API key in query.
- GET
https://api.geoapify.com/v1/geocode/reverseno statusReverse-geocode a (lat, lon) pair to a place suggestion (map picker, prestation).
RequestQuery: lat=:lat, lon=:lon, limit=1, format=json, apiKey=:GEOAPIFY_API_KEY
ResponseMapPlaceSuggestion | null
lib/src/core/services/geoapify_service.dart:80 // reverseGeocodeauth: API key in query.
Notes
Static class with a private constructor — intentional; no DI wrapper. Tests must override at the top of the static cache (or wrap into a provider in the future). All endpoints below hit https://api.geoapify.com/v1 (NOT the Naow backend).