arch-atlas

Geoapify Service

core/services/geoapify_service.dart

data

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

  1. isConfigured gates every call — falls back to empty results when GEOAPIFY_API_KEY is missing.
  2. autocomplete: text + optional bias (lat/lon) + limit; returns MapPlaceSuggestion[].
  3. geocode: text → single best match.
  4. 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

  • GEThttps://api.geoapify.com/v1/geocode/autocompleteno status

    Place autocomplete for address fields across search, map picker, checkout, prestation.

    Request
    Query: 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 // autocomplete

    auth: API key in query. Bias uses Geoapify's lon,lat ordering. Default 5s timeout — flaky network surfaces as empty list, not error.

  • GEThttps://api.geoapify.com/v1/geocode/searchno status

    Forward-geocode a single query string to a place.

    Request
    Query: text=:q, limit=1, format=json, apiKey=:GEOAPIFY_API_KEY
    Response
    { results: [first] } → MapPlaceSuggestion | null
    lib/src/core/services/geoapify_service.dart:56 // geocode

    auth: API key in query.

  • GEThttps://api.geoapify.com/v1/geocode/reverseno status

    Reverse-geocode a (lat, lon) pair to a place suggestion (map picker, prestation).

    Request
    Query: lat=:lat, lon=:lon, limit=1, format=json, apiKey=:GEOAPIFY_API_KEY
    Response
    MapPlaceSuggestion | null
    lib/src/core/services/geoapify_service.dart:80 // reverseGeocode

    auth: 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).