geohasher 0.5.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

geohasher #

Dart port of geohash; provides encoding and decoding of string geohashes.

Original work and additional ports at:

testing #

The primary validation strategy for this port was checking it against other implementations.

These tools confirm it plays nice with Go:

dart tool/generate-testcases-dart/main.dart | go run tool/validate-testcases-go/main.go
go run tool/generate-testcases-go/main.go | dart tool/validate-testcases-dart/main.dart

These tools confirm it plays nice with Python:

dart tool/generate-testcases-dart/main.dart | python tool/validate-testcases-python/
python tool/generate-testcases-python/ | dart tool/validate-testcases-dart/main.dart

These tools confirm it's self consistent:

dart tool/generate-testcases-dart/main.dart | dart tool/validate-testcases-dart/main.dart

0.5.2 #

  • Correcting another package name reference; this is geohasher, not geohash.

0.5.1 #

  • Correcting library name; was geohash, now geohasher
  • Providing an extended description to clarify what the package does
  • Use contains instead of indexOf

0.5.0 #

  • Initial version, created by Levi Cook


import 'package:geohasher/geohasher.dart';

void main() {
  // Run this with assertions enabled:
  // $ dart --enable-asserts example/geohash_example.dart
  //        ^^^^^^^^^^^^^^^^

  final lat = 33.85679995, lon = 151.21530013;

  final hash = encode(lat, lon);
  assert(hash == 'xq588grw5uun');

  assert(encode(lat, lon, precision: 2) == 'xq');
  assert(encode(lat, lon, precision: 4) == 'xq58');

  final latLon = decode(hash);
  assert(lat == latLon.latitude, '$lat, $latLon');
  assert(lon == latLon.longitude, '$lon, $latLon');
  assert(latLon == latLon, 'LatLon implements ==');
  assert(latLon.hashCode == latLon.hashCode, 'LatLon implements hashCode');

  assert(neighbor(hash, Direction.north) == 'xq588grw5uup');
  assert(neighbor(hash, Direction.northEast) == 'xq588grw5uur');
  assert(neighbor(hash, Direction.southEast) == 'xq588grw5uum');
  assert(neighbor(hash, Direction.south) == 'xq588grw5uuj');
  assert(neighbor(hash, Direction.southWest) == 'xq588grw5ugv');
  assert(neighbor(hash, Direction.west) == 'xq588grw5ugy');
  assert(neighbor(hash, Direction.northWest) == 'xq588grw5ugz');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  geohasher: ^0.5.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:geohasher/geohasher.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
args ^1.5.2
test ^1.6.4