geohasher 0.5.2

geohasher #

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

Original work and additional ports at: https://www.movable-type.co.uk/scripts/geohash.html

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/main.py
python tool/generate-testcases-python/main.py | 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

example/geohasher_example.dart

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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:geohasher/geohasher.dart.

Dependencies

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