geocode_cache library
A Flutter package for caching reverse geocoding and place search results locally using Hive CE.
Coordinates within a configurable radius (default 10 m) of a previously resolved location are served from cache, saving geocoding API quota.
Quick start
import 'package:geocode_cache/geocode_cache.dart';
// Configure (optional — call before init)
GeocodingService.instance.configure(
options: const GeocodeCacheOptions(
cacheRadiusMeters: 15,
maxAge: Duration(days: 7),
),
);
// Initialise once
await GeocodingService.instance.init();
// Use anywhere
final address = await GeocodingService.instance
.getAddressFromCoordinates(-8.6705, 115.2126);
print(address);
Features
- Haversine-based proximity matching with configurable radius
- Optional TTL (time-to-live) for cache entries
- Place search caching via Nominatim
- Custom address formatting
- LRU-style eviction when cache reaches max size
- Manual cache management (clear, evict stale entries)
Classes
- CachedGeocode
- A Hive-persisted model representing a cached reverse geocoding result.
- CachedGeocodeAdapter
- CachedPlaceSearch
- A Hive-persisted model representing a cached place search result.
- CachedPlaceSearchAdapter
- GeocodeCacheOptions
- Configuration options for GeocodingService.
- GeocodingService
- A geocoding service that caches reverse geocoding and place search results locally using Hive CE to reduce API calls.