geohex 3.2.0+5

GeoHex for Dart #

pub package Coverage Status Build Status

Implementation of GeoHex encoding for Dart language.

Usage #

Encoding example:

import 'package:geohex/geohex.dart';

main() {
  //Location of Capetown
  String geoHexCode = GeoHex.encode(-33.91522085, 18.3758784, 4); //OM4138

Decoding example:

import 'package:geohex/geohex.dart';

main() {
  //Geocode of Capetown
  Zone geoHexZone = GeoHex.decode('OM4138'); // instance of Zone with lat -33.91522085 lon 18.3758784 and level 4

Note #

This realisation has some difference with the original lib. It's location clamping. Original lib uses double representation of lat'n'lon, so theoretically, it should take more precision etc. but in fact, it leads to errors.

Refer to this - decimal degrees, eight points after dot the should be enough for everything.

3.2.0+1 #

  • Initial version.
  • Precision clamping

3.2.0+2 #

  • Added some tests

3.2.0+3 #

  • Added missing export of zone.dart, thanx synw

3.2.0+4 #

  • Renamed clamp to clampPrecision
  • Internal code minificatication
  • Improved test coverage
  • Separated unit test and testcases
  • Fixed potential crash in adjustXY method

3.2.0+5 #

  • merged back geohex_net test file into geohex_test
  • added more tests


import 'dart:math' as math;

import 'package:geohex/geohex.dart';

void main() {
  final geoHexCode = GeoHex.encode(-33.91522085, 18.3758784, 4); //Capetown

  final a = GeoHex.decode('XM488507762');
  final b = GeoHex.decode('XM488531402');

  final len = math.sqrt(math.pow(b.x - a.x, 2) + math.pow(b.y - a.y, 2));

  print('${len * a.hexSize} 鯨尺');
  print('${(len * a.hexSize) / (25 / 66)}m');
  print('${(len * a.hexSize) / (10 / 33)}m');

Use this package as a library

1. Depend on it

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

  geohex: ^3.2.0+5

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:geohex/geohex.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 Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
pedantic ^1.8.0+1
test ^1.8.0