搜索插件、代码仓与 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();

所属分类

源码仓库

使用此插件的项目

暂无相关数据。