搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.0

georange

一個用於編碼地理哈希、解碼地理哈希、計算兩點之間距離以及生成緯度和經度範圍的地理哈希,以幫助查詢資料庫(僅在 Firestore 上測試過)。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
263
喜歡數
33
Pub 分數
150

安裝套件

flutter pub add georange

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

georange 是一個用於地理定位任務的 Flutter/Dart 套件,支援地理哈希編碼與解碼、計算兩點之間的距離,以及產生經緯度範圍的地理解碼。這些功能特別適用於優化地理空間應用中的資料庫查詢,並針對 Firestore 進行了特定的測試與最佳化。該套件支援 Android、iOS、Web、macOS、Windows 與 Linux 多個平台,適用於跨平台開發。

適用情境

  • 地理空間資料索引
  • 基於 Firestore 的位置查詢
  • 坐標之間的距離計算
  • 即時位置追蹤
  • 位置感知搜尋功能
  • 高效基於範圍的資料庫篩選

主要特色

  • 地理哈希編碼與解碼
  • 兩點之間的距離計算
  • 用於查詢的地理由哈希範圍產生
  • 針對 Firestore 優化
  • 跨平台相容性
  • 地理空間操作的簡單 API

適合對象

  • 開發基於位置應用程式的開發者
  • 需要高效地理空間資料庫查詢的應用程式
  • 使用 Firestore 存儲地理定位資料的專案
  • 跨平台行動與Web應用
  • 需要快速鄰近搜尋的應用程式

使用建議

  • 主要在 Firestore 上進行測試
  • 限於基於geohash的空間索引
  • 需要理解地理哈希概念
  • 未針對非地理空間資料庫進行優化
  • 依賴於準確的座標輸入
  • 可能需要額外的邏輯來處理邊緣情況的空間查詢

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。