h3_core
Dart/Flutter bindings for the H3 geospatial indexing library, originally developed at Uber.
Wraps H3 v4.4.1 via dart:ffi on native platforms and h3-js via dart:js_interop on web. Same API on all platforms.
Features
- Full H3 v4.4.1 API (~80 functions)
- Native: zero-overhead FFI calls via Build Hooks (compiles C natively — no pre-built binaries)
- Web: h3-js interop via
dart:js_interop - Single package, identical API on all platforms
- Type-safe Dart API with extension types (
H3Index,LatLng,CellBoundary) - Async wrappers for heavy operations
Platform Support
| Platform | Backend | CI Tested |
|---|---|---|
| Android | dart:ffi (C) | via macOS build |
| iOS | dart:ffi (C) | via macOS build |
| macOS | dart:ffi (C) | macOS stable |
| Linux | dart:ffi (C) | Ubuntu stable + beta |
| Windows | dart:ffi (C) | Windows stable |
| Web | h3-js (JS) | Chrome stable |
Installation
dependencies:
h3_core: ^1.0.4
Quick Start
import 'package:h3_core/h3_core.dart';
// Convert coordinates to H3 cell
final cell = latLngToCell(LatLng(37.7749, -122.4194), 9);
print(cell.toHex()); // 89283082803ffff
// Get cell center
final center = cellToLatLng(cell);
print('${center.lat}, ${center.lng}');
// Get neighbors
final neighbors = gridDisk(cell, 1); // 7 cells (origin + 6 neighbors)
// Check cell properties
print(getResolution(cell)); // 9
print(isValidCell(cell)); // true
print(isPentagon(cell)); // false
API Overview
Indexing
latLngToCell— Convert coordinates to H3 cellcellToLatLng— Get cell center pointcellToBoundary— Get cell boundary vertices
Inspection
getResolution,getBaseCellNumber,isValidCell,isPentagon,isResClassIIIgetIcosahedronFaces,isValidIndex,isValidDirectedEdge,isValidVertex
Traversal
gridDisk,gridDiskDistances— Get cells within k distancegridRing— Get hollow ring at distance kgridDistance— Distance between two cellsgridPathCells— Line of cells between two cells
Hierarchy
cellToParent,cellToChildren,cellToCenterChildcellToChildPos,childPosToCellcompactCells,uncompactCells
Directed Edges
areNeighborCells,cellsToDirectedEdgegetDirectedEdgeOrigin,getDirectedEdgeDestinationoriginToDirectedEdges,directedEdgeToBoundary
Vertices
cellToVertex,cellToVertexes,vertexToLatLng
Measurements
greatCircleDistanceKm,greatCircleDistanceMcellAreaKm2,cellAreaM2edgeLengthKm,edgeLengthMgetHexagonAreaAvgKm2,getHexagonEdgeLengthAvgKmgetNumCells
Regions
polygonToCells— Fill polygon with cellscellsToMultiPolygon— Convert cells to polygon boundaries
Coordinates
cellToLocalIj,localIjToCell
Async
polygonToCellsAsync,gridDiskAsync,compactCellsAsync,uncompactCellsAsync
Web Setup
Add the h3-js script tag to your web/index.html before the Flutter bootstrap:
<script src="https://unpkg.com/h3-js"></script>
<script src="flutter_bootstrap.js" async></script>
Versioning
Package version uses its own semver. Wraps H3 C library v4.4.1.
License
Apache 2.0 (matching H3)
Libraries
- h3_core
- H3 geospatial indexing for Dart/Flutter.