Search packages, repositories and app categories

Package detailsv1.0.0

georange

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).

AndroidiOSWebmacOSWindowsLinux
30-day downloads
263
Likes
33
Pub points
150

Install package

flutter pub add georange

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

georange is a Flutter/Dart package designed for geolocation tasks, enabling geohash encoding and decoding, calculating distances between two geographic points, and generating latitude and longitude ranges as geohashes. These features are particularly useful for optimizing database queries in geospatial applications, with specific testing and optimization for Firestore. The package supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, making it versatile for cross-platform development.

Use cases

  • Geospatial data indexing
  • Firestore-based location queries
  • Distance calculation between coordinates
  • Real-time location tracking
  • Location-aware search features
  • Efficient range-based database filtering

Key features

  • Geohash encoding and decoding
  • Distance calculation between two points
  • Generation of geohash ranges for queries
  • Optimized for Firestore
  • Cross-platform compatibility
  • Simple API for geospatial operations

Suitable for

  • Developers building location-based apps
  • Apps requiring efficient geospatial database queries
  • Projects using Firestore with geolocation data
  • Cross-platform mobile and web applications
  • Applications needing fast proximity searches

Considerations

  • Primarily tested on Firestore
  • Limited to geohash-based spatial indexing
  • Requires understanding of geohash concepts
  • Not optimized for non-geospatial databases
  • Depends on accurate coordinate input
  • May need additional logic for edge-case geospatial queries

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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

Categories

Source repository

Projects using this package

No data available yet.