GithubHelp home page GithubHelp logo

trendingtechnology / georange Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cngeru/georange

0.0 1.0 0.0 9 KB

A package that helps with encoding and decoding of geohashes.

Home Page: https://pub.dev/packages/georange

License: MIT License

Dart 100.00%

georange's Introduction

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();

georange's People

Contributors

cngeru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.