Dart and Flutter
teigeodata in Flutter apps and Dart programs on Android, iOS, desktop and the web: offline places with rows as maps.
One package for Dart and Flutter on Android, iOS, macOS, Linux, Windows and the web. Natively it calls the C library through FFI, supplied by the package's build hook; on the web (dart2js or dart2wasm) the same classes run on the WebAssembly module.
Every example on this page ran
The code below is cut from one program, the tour, which CI runs on the released
public pack world-np-lite.tgd (data-2026.11.14.3) and checks line by line against the
output shown here. The output is the same in every language.
Install
From the first registry release:
dart pub add teigeodata # or: flutter pub add teigeodataDart 3.10 or later (Flutter 3.38 or later). The build hook fetches the prebuilt library for the
target and checks it against the SHA-256 the package pins; library: names one you built,
prebuilt_base: a mirror.
Get a pack
Queries read packs: signed, memory-mapped files of places. This guide uses the world lite pack: the world's countries, first-level units and cities of 5,000 or more, India's districts and statutory towns, and Nepal in full, 172,339 places named in Nepali, Hindi and English (15.6 MB, CC BY 4.0):
curl -LO https://github.com/teispace/teigeodata/releases/download/data-2026.11.14.3/world-np-lite.tgd
shasum -a 256 world-np-lite.tgd # 243ae55509a538b1f61da50994a791cc78e7deb70bb4bf743b9f59d458cbe3f3An app ships a pack inside its bundle, or downloads one when a user needs it. Once the signed catalog is live, the store does that download for you: it verifies every byte and keeps the packs updated.
Read a result
Every query returns a result blob (Uint8List): the rows as compact columns, read in
place. Reader reads it; iterating gives each row as a Map<String, Object?>, with null where
a value is null. Dart records make the numbers easy to pull out:
for (final p in Reader(engine.search('Pokhara', 3))) {
final (lat, lon) = (p['lat'] as double, p['lon'] as double);
print('${p['name']} $lat, $lon');
}Reader(blob).single takes the one row of a lookup. Whole columns: numbers('lat'),
strings('name'), nulls('elevation').
import 'dart:convert';
import 'package:teigeodata/teigeodata.dart';
Open a pack
An Engine holds the packs it answers from. openFile memory-maps a pack file and
adds it as a layer; the engine answers from every layer at once, and a higher layer wins
where two disagree. Opening is cheap: the head of the file is read and checked and the block hashes of large
sections are proved; each section is verified against its hash the first time a query reads
it.
await TeiGeodata.init(); // loads the module on the web; returns at once natively
final tg = TeiGeodata();
final engine = Engine(tg);
engine.openFile(pack);
print('layers: ${engine.layers()}');layers: 1openBytesadds a pack from bytes already in memory (a download, an app asset, the browser).openFileRangeopens a pack stored uncompressed inside another file, such as an Android APK.- Each
…Withform takesOpenOptions: precedence over the other packs, when sections are verified (lazy, eager or trusted), whether the file is mapped or read, and which components, languages and outline level to read. openFilereturns the layer's number;removetakes it out again while other threads keep querying. One engine answers from any number of threads at once.
Search by name
search finds places by name, best first. It matches every name a place has, in every
script, and forgives spelling: काठमाडौं, Kathmandu and Kathamandu find the same city, and so do
typos, missing accents and abbreviations. A result row has the place columns (id, name,
kind, level, lat, lon, elevation, parent, tz, iso, population,
population_kind) and a score.
for (final p in Reader(engine.search('Pokhara', 3))) {
final (lat, lon) = (p['lat'] as double, p['lon'] as double);
print(
'${p['id']} ${p['name']} ${p['kind']} ${lat.toStringAsFixed(4)}, '
'${lon.toStringAsFixed(4)} score ${p['score']}',
);
}tgd:np/1xhb Pokhara settlement 28.2669, 83.9680 score 132
tgd:np/1xnr Pokhara admin 28.2094, 83.9818 score 105
tgd:np/15t1 Pokhara settlement 28.0636, 82.3786 score 90The score ranks the rows of one query and means nothing across queries. It adds how well the
name matched to how important the place is, so a city ranks above a village of the same name.
limit is at most 10,000 (TeiGeodata.limitMax).
Narrow a search by its parent
Write the place's parent after a comma, as people do: "Kathmandu, Bagmati". Places
inside a unit of that name rank first; the parent can be any ancestor (a district, a province,
a country) and is matched with the same tolerance as the name.
for (final p in Reader(engine.search('Kathmandu, Bagmati', 2))) {
print('${p['id']} ${p['name']} ${p['kind']} ${p['level']}');
}tgd:np/2cn Kathmandu settlement 0
tgd:np/2gm Kathmandu admin 3The city (a settlement, level 0) and the metropolitan municipality (an admin unit at level 3) share the name, and both are in Bagmati.
Rank by distance from a point
Many places share a name. searchWith takes SearchOptions: a focus point (the
user's location, or the middle of the map they are looking at) ranks near places first. A place
at the focus gains 30 points, one focusScaleM away 15, and the gain keeps halving with
distance (the default scale is 50 km).
// Many places share a name; a focus (the user's location) ranks the near ones first.
const options = SearchOptions(
focusLat: 28.7,
focusLon: 80.6,
focusScaleM: 30000,
);
for (final p in Reader(engine.searchWith('Shivapur', 3, options))) {
final (lat, lon) = (p['lat'] as double, p['lon'] as double);
print(
'${p['id']} ${p['name']} ${lat.toStringAsFixed(4)}, ${lon.toStringAsFixed(4)}',
);
}tgd:np/2v99 Shivapur 28.5310, 80.8213
tgd:np/2raj Shivapur 28.7141, 80.9869
tgd:np/2rkx Shivapur 28.5061, 81.3032Set strict to rank by how well the name matched first (exact, loose, prefix, one edit,
substring, two edits, phonetic), then by importance and focus, instead of one combined score:
useful for an autocomplete that must show exact matches on top.
Get a place by its ID
Every place has a stable ID such as tgd:np/1xhb: the country, then a short code. IDs
survive rebuilds of the data; when two places are merged, get on the retired ID answers
with the survivor, so IDs you stored keep working.
final place = Reader(engine.get('tgd:np/1xhb')).single;
print('${place['name']} ${place['kind']}');
final (lat, lon) = (place['lat'] as double, place['lon'] as double);
print(
'at ${lat.toStringAsFixed(6)}, ${lon.toStringAsFixed(6)}, ${place['elevation']} m',
);
print('timezone ${place['tz']} parent ${place['parent']}');Pokhara settlement
at 28.266890, 83.968000, 1006 m
timezone Asia/Kathmandu parent tgd:np/1xnrelevation is metres above mean sea level (EGM2008), tz the IANA zone and parent the
ID of the unit that holds the place. Any column may be null where the data has no value: read
each through the reader, which gives your language's null.
Walk the admin hierarchy
ancestors lists the units that hold a place, parent first, up to its country; parent
gives the first of them alone and children the units and places one level down.
for (final p in Reader(engine.ancestors('tgd:np/1xhb'))) {
print(
'${p['kind']} ${p['level']} ${p['name']} ${p['iso'] ?? ''}'.trimRight(),
);
}
final children = Reader(engine.children('tgd:np/295c'));
print('Kaski has ${children.rows} children');admin 3 Pokhara
admin 2 Kaski
admin 1 Gandaki NP-P4
country 0 Nepal NP
Kaski has 5 childrenlevel is the admin level as each country defines it: 0 is a country (and a settlement,
which is not a unit), 1 a province or state, and so on down to the lowest level the data has.
Each country's ladder is in its profile on the data pages.
Reverse geocode a point
reverse gives the places nearest a point, nearest first, each with meters (the
great-circle distance) and bearing (degrees clockwise from north, from the place to the
point: "3.2 km at 45° from Pokhara").
for (final p in Reader(engine.reverse(27.7172, 85.3240, 3))) {
final (meters, bearing) = (p['meters'] as double, p['bearing'] as double);
print(
'${p['name']} ${meters.toStringAsFixed(0)} m at ${bearing.toStringAsFixed(0)}°',
);
}Narayanhiti Royal Palace 331 m at 116°
Gairidhara 375 m at 220°
Naxal 384 m at 329°For the admin units that hold a point (its district, province and country) use
adminAt below; reverse answers with what is near it.
Find everything within a radius
withinRadius gives the places within a distance of a point, nearest first, with the
same meters and bearing columns, at most limit of them.
final within = Reader(
engine.withinRadius(27.7172, 85.3240, 500, 10),
).records();
final farthest = within.last['meters'] as double;
print(
'${within.length} places within 500 m; farthest ${farthest.toStringAsFixed(0)} m',
);3 places within 500 m; farthest 384 mFind places near a place
nearby is reverse geocoding from a place you already have: the places nearest it,
itself left out.
for (final p in Reader(engine.nearby('tgd:np/2cn', 3))) {
print('${p['name']} ${(p['meters'] as double).toStringAsFixed(0)} m');
}Bhrikuti Mandap 168 m
Bagbazar 354 m
Shahidgate 393 mAdmin units at a point, and ISO 3166 codes
adminAt tests the point against the admin boundaries and gives every unit that holds
it, country first. byIso finds a country or a subdivision by its ISO 3166 code (NP,
NP-P4, in either case).
for (final p in Reader(engine.adminAt(28.2096, 83.9856))) {
print('${p['level']} ${p['name']} ${p['iso'] ?? ''}'.trimRight());
}
final state = Reader(engine.byIso('NP-P4')).single;
print('NP-P4 is ${state['name']} ${state['id']}');0 Nepal NP
1 Gandaki NP-P4
2 Kaski
3 Pokhara
NP-P4 is Gandaki tgd:np/2922Boundaries are exact polygons, so a point near a border is answered by the side it is on, not by the nearest centre. Disputed boundaries are drawn from one stated perspective; see accuracy.
Timezones: the zone, its offset and local times
tzAt gives the IANA zone at a point as the zone boundaries draw it. With the zone,
tzOffsetAt gives the UTC offset at an instant (from the tzdb rules inside the pack, not
from the operating system), and tzLocal tells whether a wall-clock time exists: unique,
gap (skipped by a daylight-saving change) or overlap (it happens twice), with the offsets
before and after.
final zone = Reader(engine.tzAt(27.7172, 85.3240)).single['tz'] as String;
final offset = Reader(engine.tzOffsetAt(zone, 1700000000)).single;
print(
'$zone ${offset['seconds']} s east of UTC, ${offset['abbr']} dst ${offset['dst']}',
);
final local = Reader(
engine.tzLocal('America/New_York', 2026, 3, 8, 2, 30, 0),
).single;
print(
'02:30 on 2026-03-08 in New York: ${local['kind']} ${local['before']} -> ${local['after']}',
);
print('tzdb ${engine.tzVersion()}');Asia/Kathmandu 20700 s east of UTC, +0545 dst 0
02:30 on 2026-03-08 in New York: gap -18000 -> -14400
tzdb 2026ftzVersion names the tzdb release the rules come from, so you can tell when a pack is
older than a rule change; tzZones lists every zone the packs hold.
Elevation at any point
elevationAt reads the terrain height at a point from the pack's elevation grid,
interpolated between the four samples around it: meters above EGM2008, the source product,
the grid's resolution_m and the datum. There is no row at sea or outside every grid.
final height = Reader(engine.elevationAt(27.7172, 85.3240)).single;
final (meters, grid) = (
height['meters'] as double,
height['resolution_m'] as double,
);
print(
'${meters.toStringAsFixed(1)} m above ${height['datum']} '
'(${height['source']}, ${grid.toStringAsFixed(0)} m grid)',
);1304.2 m above EGM2008 (nasadem, 464 m grid)Every place also has its own elevation column. The world pack carries a coarse grid; a
country's terrain pack adds a finer one, and the engine answers from the finest grid that covers
the point.
Distance and bearing
distanceM is the great-circle distance in metres (haversine on the WGS84 mean
sphere, within about 0.5% of the ellipsoid), and bearingDeg the initial bearing from the
first point to the second, in degrees clockwise from north. Neither needs a pack. Between two
places you already have, distance takes their IDs and answers one row with meters and
bearing.
final km = tg.distanceM(27.7172, 85.3240, 28.2096, 83.9856) / 1000;
final heading = tg.bearingDeg(27.7172, 85.3240, 28.2096, 83.9856);
print('Kathmandu to Pokhara: ${km.toStringAsFixed(1)} km, heading ${heading.toStringAsFixed(0)}°');
final apart = Reader(engine.distance('tgd:np/2cn', 'tgd:np/1xhb')).single;
final (far, bearing) = (apart['meters'] as double, apart['bearing'] as double);
print('place to place: ${(far / 1000).toStringAsFixed(1)} km at ${bearing.toStringAsFixed(0)}°');Kathmandu to Pokhara: 142.4 km, heading 293°
place to place: 146.9 km at 296°distance answers no row when either ID is unknown. From a point to a place, pass the
place's lat and lon to distanceM. The bearing is the direction you set off in: on a
great circle it changes along the way, so the bearing back is not the reverse of this one.
A place's outline
boundary answers a unit's outline as one row: geojson, an RFC 7946 Feature (a
Polygon or MultiPolygon, outer rings counterclockwise and holes clockwise, seven decimals as
stored), with the lod read, its tolerance_m and the number of vertices. A place with no
outline answers its point as the geometry; an unknown ID answers no row.
final shape = Reader(engine.boundary('tgd:np/2gm', 0)).single;
final geojson = shape['geojson'] as String; // a GeoJSON Feature, for any map library
final feature = jsonDecode(geojson) as Map<String, dynamic>;
print('${feature['geometry']['type']} of ${shape['vertices']} vertices at level ${shape['lod']}');
final tolerance = shape['tolerance_m'] as double;
print('tolerance ${tolerance.toStringAsFixed(0)} m, ${utf8.encode(geojson).length} bytes of GeoJSON');Polygon of 176 vertices at level 0
tolerance 0 m, 4362 bytes of GeoJSONThe Feature goes to a map as it is: MapLibre's and Leaflet's GeoJSON sources, OpenLayers,
Shapely's shape(), Turf and JTS all read it.
- Level of detail.
lod0 is full resolution; 1 to 6 are coarser, each within itstolerance_m, with neighbouring units still sharing their borders at every level. A pack stored at full resolution only (the lite packs) answers every level as 0. A country at level 0 can be megabytes: draw a coarser level, and keep 0 for measuring. lodabove 6 isInvalidArgument; a pack installed withoutboundariesisMissingComponent.- Whether a point is inside a unit is
adminAt, which tests the same outlines without building them.
Errors
A call fails with one of eight stable codes, the same in every language:
| Code | Meaning |
|---|---|
InvalidArgument | An argument is outside its range: a latitude of 91, a limit over 10,000, a malformed ID. |
MissingComponent | The query needs a component the pack was installed without (search on a pack installed without search). |
Corrupt | The bytes are not a valid pack, or a section does not match its hash. |
Io | A file could not be read. |
Network | No mirror answered, or the connection broke (the store only). |
Refused | The store refused: the catalog did not verify, a pack is not installed or another needs it. |
Cancelled | A callback or a job was asked to stop. |
Internal | A bug inside teigeodata; a panic never crosses into your program. |
A query that finds nothing is not an error: it returns no rows.
Each code is a subclass of TeiGeodataException: InvalidArgumentException,
MissingComponentException and so on:
try {
engine.reverse(91, 0, 1);
} on InvalidArgumentException catch (error) {
print('invalid argument: ${error.message}');
}invalid argument: (91, 0) is not a point: the latitude is outside -90 to 90 degreesFlutter
- Await
TeiGeodata.init()once before the first engine. Natively it returns at once; on the web it loads the WebAssembly module, whose files go inweb/teigeodata_wasm/. - Bundle a pack as an asset and open it from its bytes
(
engine.openBytes((await rootBundle.load('assets/world-np-lite.tgd')).buffer.asUint8List())), or copy it to the app's documents directory once andopenFileit there to map it instead. - Isolates. Queries take microseconds and are fine on the UI isolate. The store's blocking
calls have
…Asyncforms that run on another thread, and aJobstreams its progress. cargo xtask flutter-checkruns the package's integration test in a Flutter app on the desktop, an iOS simulator or an Android device.
The whole program
Run it from a checkout of the repository, which builds what the language needs, fetches the pinned pack and compares the output:
cargo xtask docs-examples --fetch --check --lang dart