A package that helps with encoding and decoding of geohashes.

Related tags

Utilities georange
Overview

georange

Dart License: MIT Pub Version

Georange is a package that helps with encoding geohashes, decoding geohashes,calculating distance between 2 points and generating latitudinal and longitudinal ranges as geohashes to help with the querying of databases (Tested on Firestore Only).

Heavily influenced by GeoFlutterFire

Buy Me A Coffee

Getting Started

You should ensure that you add Georange as a dependency in your flutter project.

dependencies:
  georange: <latest-version>

You should then run flutter packages get

Example

There is a detailed example project in the example folder.

Initialize

Import georange to your dart file and initialize

import 'package:georange/georange.dart';
GeoRange georange = GeoRange();

Encode LatLng

This method encodes the latitude and longitude

var encoded = georange.encode(-1.2862368,36.8195783);
print(encoded);

prints kzf0tvg5n

Decode Geohash

Decode a [geohash] into a pair of latitude and longitude.

Point decoded = georange.decode("kzf0tvg5n");
print(decoded);

prints -1.2862372398376465 36.819584369659424

Generate Range

  Range range = georange.geohashRange(-1.2921, 36.8219, distance: 10);
  print(range.lower);
  print(range.upper);

prints kzf05k6hh kzf30mptu

Calculate Distance between 2 Points

  Point point1 = Point(latitude: -4.0435, longitude: 39.6682); //Mombasa
  Point point2 = Point(latitude: -1.2921, longitude: 36.8219); // Nairobi

  var distance = georange.distance(point1, point2);
  print(distance);

prints 439.716 Distance in Kilometres

Usage with Firestore

  1. Add a document to firestore with a geohash field or a different name
  final FirebaseFirestore _db;
  ...
  String myhash = georange.encode(-1.2862368,36.8195783);
  await _db.collection("locations").add({
    "geohash":myhash,
  })
  ...
  1. Query Firestore (Runs like a normal firestore query)
final FirebaseFirestore _db;

GeoRange georange = GeoRange();

Range range = georange.geohashRange(currentLocation.latitude, currentLocation.longitude, distance:10);

QuerySnapshot snapshot = await _db
 .collection("locations")
 .where("geohash", isGreaterThanOrEqualTo: range.lower)
 .where("geohash", isLessThanOrEqualTo: range.upper)
 .limit(10)
 .get();
You might also like...

This package wraps Airtime, Sms, and Voice call from Africa's Talking APIs.

This package wraps some functionalities from Africa's Talking API The functionalities implemented are; Sms send message fetch messages generate checko

May 31, 2022

Let's Encrypt support for the shelf package (free and automatic HTTPS certificate support).

shelf_letsencrypt shelf_letsencrypt brings support for Let's Encrypt to the shelf package. Usage To use the LetsEncrypt class import 'dart:io'; impor

Oct 31, 2022

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Dec 13, 2022

A dart package for decode and encode emv QR code

A dart package for decode and encode emv QR code

Nov 15, 2022

WhatsApp API package for flutter, to send message and product information.

WhatsApp API package for flutter, to send message and product information.

WhatsApp API package for flutter, to send message and product information. Platform Support Android iOS MacOS Web Linux Windows ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ What

Nov 11, 2022

This is a simple class to package up and send requests to the Kroki.io web service.

Kroki.dart This is a simple class to package up and send requests to the Kroki.io web service. A live editor to editing diagrams that Kroki supports c

Jun 8, 2022

Dio Package in Flutter - HTTP Requests and Interceptors.

Dio Package in Flutter - HTTP Requests and Interceptors.

Dio Package in Flutter - HTTP Requests and Interceptors. Learn how to use Flutter Dio package to make http requests, deal with interceptors and take care of unexpected server responses and failures in Flutter apps.

Nov 18, 2022

Dart package for random strings and numbers, with weights

randomness Dart package for random strings and numbers, with weights Random strings, numbers. RNG with weights. Cryptographically secure options. Gett

Aug 6, 2022

A pure dart package to apply useful rate limiting strategies on regular functions.

A pure dart package to apply useful rate limiting strategies on regular functions.

Rate limiting is a strategy for limiting an action. It puts a cap on how often someone can repeat an action within a certain timeframe. Using rate_limiter we made it easier than ever to apply these strategies on regular dart functions.

Dec 14, 2022
Comments
  • Pagination

    Pagination

    Hello again,

    I am attempting to paginate my results using the query

    
    

    The query works when not using start after document,

    However app crashes and returns error message when:

    opened by torphix 9
  • Unwanted query results

    Unwanted query results

    There seems to be a problem with the geo query. No matter the distance in longitude, the query picks everything that's beyond the radius limit. It does work when applied laterally, meaning it discards results in latitude. I suggest to try to create a scenario where you have several items with similar latitude., but vastly different values in longitude. You will notice that the query picks up results that are double the required distance.

    /W

    opened by Cardenaz 4
  •  Unhandled Exception: RangeError (index): Invalid value

    Unhandled Exception: RangeError (index): Invalid value

    [VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0

    Seems to be working fine, except when no items within range distance. It throws the above mentioned error

    opened by ericel 1
  • I think the query is flawed

    I think the query is flawed

    There are multiple reports of incorrect results.

    Querying by the lower and upper geohash range, seems to be incorrect. As you need to query around the geohash centre point.

    But the range finds every geohash between the upper and lower, lexicographically. Which in some cases, will find geohashes which aren't actually close to the centre point and misses others that are close.

    Other packages use bounding boxes etc to query geohashes, which would find the cluster of geohashes around the centre point.

    opened by didnteven 0
Morphological analysis of Japanese sentences. This Flutter plugin helps you to analyze Japanese sentences.

ringo ringo is japanese word separator. Usage final ringo = await Ringo.init(); final tokenized = ringo.tokenize('吾輩はRingoである'); print('tokenized: $to

ryo 8 Oct 31, 2022
A flutter project that helps you visualise the sorting algorithms.

SortViz A flutter project that helps you visualise various sorting algorithms. Description A sorting visualizer that visualises different sorting algo

Mahima Goyal 3 Sep 7, 2021
MB Contact Form is a basic flutter widget which helps you for your contact page.

mb_contact_form is a third party flutter package. This is a simple version of Contact Form. This can be easily added to your flutter projects. This make your works simpler and your code shorter. This is recently updated and has null safety too.

Mouli Bheemaneti 2 Oct 17, 2022
A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully & easily modifiable.

A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully

Muhammad Hamza 20 Jun 7, 2022
null 2 Apr 17, 2022
A Dart package which supports checking if a current package is up-to-date.

pub_updater A Dart package which enables checking whether packages are up to date and supports updating them. Intended for use in CLIs for prompting u

Very Good Open Source 47 Oct 27, 2022
A flutter package provides controllers and editors for complex models and lists

This package provides controllers and editors for complex models and lists and is inspired by simplicity of TextEditingController. It encapsulates sta

null 2 Sep 1, 2022
A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

Miguel Manjarres 2 Jan 28, 2022
A Dart package to web scraping data from websites easily and faster using less code lines.

Chaleno A flutter package to webscraping data from websites This package contains a set of high-level functions that make it easy to webscrap websites

António Nicolau 30 Dec 29, 2022