All Projects → MichaelSolati → Geofirestore Js

MichaelSolati / Geofirestore Js

Licence: mit
Location-based querying and filtering using Firebase Firestore.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Geofirestore Js

Fuego
Fuego is a command line client for the firestore database (https://firebase.google.com/docs/firestore).
Stars: ✭ 110 (-74.77%)
Mutual labels:  hacktoberfest, firebase, firestore
Firextensions
[DEPRECATED] 🔥 Unofficial Kotlin Extensions for the Firebase Android SDK.
Stars: ✭ 30 (-93.12%)
Mutual labels:  hacktoberfest, firebase, firestore
Hoverboard
Conference website template
Stars: ✭ 935 (+114.45%)
Mutual labels:  hacktoberfest, firebase, firestore
Geofirex
🌐 📍 Geolocation Queries with Firestore & RxJS
Stars: ✭ 396 (-9.17%)
Mutual labels:  firebase, firestore, geolocation
Vuefire
🔥 Firebase bindings for Vue.js & Vuex
Stars: ✭ 3,234 (+641.74%)
Mutual labels:  firebase, firestore
Squanchy Android
Open source Android app for your conferences
Stars: ✭ 294 (-32.57%)
Mutual labels:  firebase, firestore
Firestore Backup Restore
NPM package for backup and restore Firebase Firestore
Stars: ✭ 307 (-29.59%)
Mutual labels:  firebase, firestore
Sapphiredb
SapphireDb Server, a self-hosted, easy to use realtime database for Asp.Net Core and EF Core
Stars: ✭ 326 (-25.23%)
Mutual labels:  firebase, firestore
crisis-news-mapper
日本の災害関連ニュースをTwitterから収集して地図上にマッピングするFirebaseプロジェクト crisis.yuiseki.net
Stars: ✭ 13 (-97.02%)
Mutual labels:  geolocation, firestore
Flutter programs
Experiments with Mobile
Stars: ✭ 308 (-29.36%)
Mutual labels:  firebase, firestore
Gmscore
Free implementation of Play Services
Stars: ✭ 4,356 (+899.08%)
Mutual labels:  firebase, geolocation
Node Firestore Import Export
Firestore data import and export
Stars: ✭ 271 (-37.84%)
Mutual labels:  firebase, firestore
React Admin Firebase
A firebase data provider for the react-admin framework
Stars: ✭ 269 (-38.3%)
Mutual labels:  firebase, firestore
Firesql
Query Firestore using SQL syntax
Stars: ✭ 304 (-30.28%)
Mutual labels:  firebase, firestore
Pring
Cloud Firestore model framework for iOS - Google
Stars: ✭ 260 (-40.37%)
Mutual labels:  firebase, firestore
Devlopr Jekyll
Build and Deploy your Static Site 🚀 using this beautiful Jekyll Framework/Theme built for Creatives
Stars: ✭ 309 (-29.13%)
Mutual labels:  hacktoberfest, firebase
Firebase Instagram
📸 Instagram clone with Firebase Cloud Firestore, Expo, and React Native 😁😍
Stars: ✭ 389 (-10.78%)
Mutual labels:  firebase, firestore
Firestore Apollo Graphql
An example of a GraphQL setup with a Firebase Firestore backend. Uses Apollo Engine/Server 2.0 and deployed to Google App Engine.
Stars: ✭ 371 (-14.91%)
Mutual labels:  firebase, firestore
Firestore Import Export
An application that can help you to backup and restore from Cloud Firestore | Firebase
Stars: ✭ 392 (-10.09%)
Mutual labels:  firebase, firestore
Tallyassist
Open source Flutter-based template for a business assistant application
Stars: ✭ 137 (-68.58%)
Mutual labels:  hacktoberfest, firebase

geofirestore

npm npm bundle size Release CI Coveralls github David GitHub stars GitHub forks

Full documentation is available at https://geofirestore.com.

GeoFirestore is an open-source library that extends the Firestore library in order to store and query documents based on their geographic location. At its heart, GeoFirestore is just a wrapper for the Firestore library, exposing many of the same functions and features of Firestore. Its main benefit, however, is the possibility of retrieving only those documents within a given geographic area - all in realtime.

GeoFirestore uses the Firebase Cloud Firestore for data storage, allowing query results to be updated in realtime as they change. GeoFirestore selectively loads only the data near certain locations, keeping your applications light and responsive, even with extremely large datasets.

GeoFirestore is designed as a lightweight add-on to Firebase. To keep things simple, GeoFirestore stores data in its own format and its own location within your Firestore database.

Table of Contents

Downloading GeoFirestore

You can install GeoFirestore via npm:

npm install geofirestore

Or you can use GeoFirestore via CDN:

<script src="https://unpkg.com/geofirestore/dist/geofirestore.js"></script>

Example Usage

Assume you are building an app to rate bars and you store all information for a bar, e.g. name, business hours and price range, and you want to add the possibility for users to search for bars in their vicinity. This is where GeoFirestore comes in. You can store each bar using GeoFirestore, using the location to build an easily queryable document. GeoFirestore then allows you to easily query which bars are nearby in a simalar fashion as geofire but will also return the bar information (not just the key or location).

Examples

You can find a full list of our demos and view the code for each of them in the examples directory of this repository. The examples cover some of the common use cases for GeoFirestore.

Documentation

Full documentation is available at https://geofirestore.com. It mostly provides the same functionality as the Firestore library, in almost the same way as the Firestore library. Many questions can be addressed by looking at the Firestore docs. However there are a few differences, and below is a little example of how to make a location based query.

import firebase from 'firebase/app';
import 'firebase/firestore';
import * as geofirestore from 'geofirestore';


// Initialize the Firebase SDK
firebase.initializeApp({
  // ...
});

// Create a Firestore reference
const firestore = firebase.firestore();

// Create a GeoFirestore reference
const GeoFirestore = geofirestore.initializeApp(firestore);

// Create a GeoCollection reference
const geocollection = GeoFirestore.collection('restaurants');

// Add a GeoDocument to a GeoCollection
geocollection.add({
  name: 'Geofirestore',
  score: 100,
  // The coordinates field must be a GeoPoint!
  coordinates: new firebase.firestore.GeoPoint(40.7589, -73.9851)
})

// Create a GeoQuery based on a location
const query = geocollection.near({ center: new firebase.firestore.GeoPoint(40.7589, -73.9851), radius: 1000 });

// Get query (as Promise)
query.get().then((value) => {
  // All GeoDocument returned by GeoQuery, like the GeoDocument added above
  console.log(value.docs);
});

Simple. Easy. And very similar with how Firestore handles a get from a Firestore Query. The difference being the added ability to say query near a center point, with a set radius in kilometers.

Limitations & Considerations

Compound Queries

Internally GeoFirestore creates multiple geohashes around a requested area. It then makes multiple inequality (<, <=, >, >=) queries and joins them together into one response. Unfortunately compound queries with inequalities or additional filtering methods such as orderBy, startAt and endAt are impossible with Firestore. To better understand this limitation, see the Firestore docs here.

Data Structure

Documents generated and stored in your Firestore collection by GeoFirestore are typed/structured as:

interface GeoDocumentData {
  g: {
    geohash: string;
    geopoint: GeoPoint;
  };
  [field: string]: any;
  }
  • g.geohash is the geohash generated by the library, and is required in order to make the geoqery.
  • g.geopoint is the GeoPoint used to generate the g.geohash field.

Data must be structured this was in order to work, and is why you should use the GeoFirestore library to insert data in order to be able to query it.

Security Rules

Because GeoFirestore adds the g field and expects a coordinates field, be sure to update your Firebase Security Rules to reflect the new fields. While not necessary for all applications, the rules below are an example of how you'd check for GeoFirestore specific fields.

match /collection/{key} {
  allow write: // Your previous rules here...
               && request.resource.data.g.size() == 2
               && request.resource.data.g.geohash is string
               && request.resource.data.g.geopoint is latlng
               && request.resource.data.coordinates is latlng
}

limit()

The limit filtering method is exposed through GeoFirestore, however there are some unique considerations when using it. Limits on geoqueries are applied based on the distance from the center. Geoqueries require an aggregation of queries. When performing a geoquery the library applies the limit on the client. This may mean you are loading to the client more documents then you intended. Use with this performance limitation in mind.

Upgrading

GeoFirestore v4.0.0+ is incompatiable with previous versions. To migrate an older GeoFirestore collection please try using this script. Be sure to read over it before executing it, it is a use at your own risk bit of code.

Contributing

All code should pass tests, as well as be well documented. Please open PRs into the dev branch. Please also see the Commit Message Guidelines for how commit messages should be structured.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].