패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소cngeru/georange

georange

지오해시의 인코딩 및 디코딩을 도와주는 패키지입니다.

georange 프로젝트 이미지
스타
9
포크
4
최근 푸시(UTC)
2021. 4. 4.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

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

Dennis Chege GitHub avatar
GitHub 작성자

Dennis Chege ↗

Nairobi
언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 1 개

  • test개발 의존성any

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗