getMarkersInBounds method
- LatLngBounds bounds
Filter cached markers for the given bounds without making API call.
Implementation
List<NewsMarker> getMarkersInBounds(LatLngBounds bounds) {
if (_cachedMarkers.isEmpty) return [];
// Check if cache is still valid.
if (_cacheTime != null) {
final elapsed = DateTime.now().difference(_cacheTime!);
if (elapsed > _cacheExpiry) {
// Cache expired, clear it.
_cachedMarkers.clear();
_cachedBounds = null;
_cacheTime = null;
return [];
}
}
// Filter cached markers that are within the requested bounds.
return _cachedMarkers.where((marker) {
return marker.location.latitude >= bounds.south &&
marker.location.latitude <= bounds.north &&
marker.location.longitude >= bounds.west &&
marker.location.longitude <= bounds.east;
}).toList();
}