dart_geohash 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

dart_geohash #

GeoHash is a simple way of storing a latitude/longitude location as a simple string.

Includes a Class for encode/decode and finding neighbors as well as a Class that can be given a location and will contain all needed information for that GeoHash.

Example #

// Create a simple geohash from a given string
GeoHash myHash = GeoHash("9yf0zhhtj");
// Immediately be able to get all other information related to it
myHash.geohash;
myHash.longitude;
myHash.latitude(decimalAccuracy: 4);
myHash.neighbors; // Returns a Map with itself and 8 surrounding neighbors
myHash.neighbor(Direction.NORTH);
// You can also create it from a specific lon/lat
GeoHash myOtherHash = GeoHash.fromDecimalDegrees(-98.1235, 38.1234);
// Separately you can use only the Geohasher functions
GeoHasher geoHasher = GeoHasher();
geoHasher.encode(-98, 38); // Returns a string geohash
geoHasher.encode(-98, 38, precision: 6) // Returns string geohash with length
geoHasher.decode("9yf0zhhtj"); // Returns decimal longitude/latitude
geoHasher.neighbors("9yf0zhhtj"); // Returns itself and 8 neighbors as a Map

#

Based on the Python Package Mapzen GeoHash

[1.0.2] - 2019.10.02 #

  • Remove unnecessary flutter requirements

[1.0.1] - 2019.10.02 #

  • Update documentation and formatting

[1.0.0] - 2019.10.02 #

  • Initial Release

example/example.dart

import 'package:dart_geohash/dart_geohash.dart';

void main() {

  GeoHasher geoHasher = GeoHasher();

  // Encoding Example
  // Given a longitude and latitude
  print(geoHasher.encode(-98, 38));
  // Including a specific precision
  print(geoHasher.encode(-98, 38, precision: 6));
  // Default precision is 12 characters
  print(geoHasher.encode(-98.123456789, 38.123456789, precision: 10));
  print(geoHasher.encode(-98.123456789, 38.123456789));
  // Specific precision that is overly precise will produce arbitrary false accuracy
  print(geoHasher.encode(-98, 38, precision: 20));

  // Decode takes a geohash and returns a List[2] with longitude and latitude
  // The results are not automatically adjusted to the accuracy (length) of the
  // given geocode. You will need to decide what degree of accuracy is required
  print(geoHasher.decode("9yf0zhhtj"));
  // Both of these will give the same geohash as shown above accuracy at
  // "human/tree" level. So be careful when determining accuracy
  print(geoHasher.encode(-98.12346696853638, 38.123438358306885, precision: 9));
  print(geoHasher.encode(-98.12346, 38.123438, precision: 9));

  // Neighbors will return the central geohash (the given one) along with the
  // 8 surrounding squares as a map with given directions
  // This will return the other geohash at all the same level of accuracy as the
  // one given
  print(geoHasher.neighbors("9yf0zhhtj"));

  /* longitude and latitude are roughly
  decimal   places 	    rough scale
  0         1.0         country
  1 	      0.1         large city
  2 	      0.01        town or village
  3 	      0.001       neighborhood
  4 	      0.0001      individual street
  5 	      0.00001     individual trees
  6 	      0.000001 	  individual humans
  */

  /* Geohash Scale
  Geohash length 	Cell width 	Cell height
  1 	              multiple countries
  2 	              state - multiple states
  3 	              multiple cities
  4 	              average city
  5 	              small town
  6 	              neighborhood
  7 	              individual street
  8 	              small store
  9 	              individual trees
  10 	              individual humans
  .....
  */


  GeoHash myHash = GeoHash("9yf0zhhtj");
  print(myHash.geohash);
  print(myHash.longitude);
  print(myHash.longitude(decimalAccuracy: 4));
  print(myHash.latitude);
  print(myHash.latitude(decimalAccuracy: 4));
  print(myHash.neighbors);
  print(myHash.neighbor(Direction.NORTH));

  GeoHash myOtherHash = GeoHash.fromDecimalDegrees(-98.1235, 38.1234);
  print(myOtherHash.geohash);
  print(myOtherHash.longitude);
  print(myOtherHash.longitude(decimalAccuracy: 4));
  print(myOtherHash.latitude);
  print(myOtherHash.latitude(decimalAccuracy: 4));
  print(myOtherHash.neighbors);
  print(myOtherHash.neighbor(Direction.NORTH));

}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/dart_geohash.dart. (-6.78 points)

Analysis of lib/dart_geohash.dart reported 14 hints, including:

line 132 col 7: DO use curly braces for all flow control structures.

line 134 col 7: DO use curly braces for all flow control structures.

line 165 col 7: DO use curly braces for all flow control structures.

line 167 col 7: DO use curly braces for all flow control structures.

line 169 col 19: Unnecessary new keyword.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.8.0