geohash_bounds 0.1.0 copy "geohash_bounds: ^0.1.0" to clipboard
geohash_bounds: ^0.1.0 copied to clipboard

Pure-Dart geohash query bounds for Firestore spatial queries, with viewport-to-cell clustering and antimeridian handling.

example/geohash_bounds_example.dart

import 'package:geohash_bounds/geohash_bounds.dart';

void main() {
  // Encode a coordinate into a geohash.
  final hash = GeohashUtil.encode(48.1351, 11.5820, precision: 9);
  print('Geohash for Munich: $hash');

  // Compute range-query bounds covering a 5 km radius, e.g. for Firestore:
  //   query.where('geohash', isGreaterThanOrEqualTo: start)
  //        .where('geohash', isLessThanOrEqualTo: end)
  final bounds = GeohashUtil.queryBounds(
    centerLat: 48.1351,
    centerLng: 11.5820,
    radiusInMeters: 5000,
  );
  for (final b in bounds) {
    print("geohash >= '${b[0]}' && geohash <= '${b[1]}'");
  }

  // Convert a map viewport to a center + radius for queryBounds.
  final circle = GeohashUtil.viewportToCircle(
    neLat: 48.20,
    neLng: 11.65,
    swLat: 48.10,
    swLng: 11.50,
  );
  print(
    'Viewport circle: (${circle.centerLat}, ${circle.centerLng}) '
    'r=${circle.radiusMeters.round()} m',
  );

  // Enumerate coarse geohash cells covering a viewport, e.g. to run one
  // aggregation count() per cell instead of fetching all documents.
  final cells = GeohashUtil.cellsForViewport(
    neLat: 55,
    neLng: 15,
    swLat: 45,
    swLng: 5,
    maxCells: 30,
  );
  print('${cells.length} cells, first prefix: ${cells.first.prefix}');
}
1
likes
160
points
137
downloads

Documentation

API reference

Publisher

verified publisherpinyourplate.app

Weekly Downloads

Pure-Dart geohash query bounds for Firestore spatial queries, with viewport-to-cell clustering and antimeridian handling.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on geohash_bounds