Skip to content

Latest commit

 

History

History
 
 

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

GeoFire Examples

GeoFire is an open-source library that allows you to store and query a set of keys based on their geographic location. At its heart, GeoFire simply stores locations with string keys. Its main benefit, however, is the possibility of retrieving only those keys within a given geographic area - all in realtime.

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

A compatible GeoFire client is also available for Objective-C and Java.

Running Locally

To run the following examples locally, clone this entire geofire repository and then simply open the example's respective index.html file in the browser of your choice.

This is a very basic example which shows you how to read from and write to GeoFire and how to handle the promises returned by the set(), get(), and remove() methods.

You can check out a live demo of this example here.

This is a more complex example which shows you how to create a GeoQuery and respond to keys moving into, out of, and within the query. It also shows how to cancel event callback registrations.

You can check out a live demo of this example here.

This example shows you how to achieve a common use case: loading only initial data. This is accomplished in GeoFire by canceling a GeoQuery once its ready event has fired.

You can check out a live demo of this example here.

The HTML5 Geolocation API allows you to get the current location of the person who is viewing your site. This demo shows how to use it to add their location to GeoFire. In addition, the examples uses Firebase's onDisconnect() method to remove their location from GeoFire when they leave the page (or close the app).

You can check out a live demo of this example here.

This demo allows you to build custom GeoQuery objects and see when fish enter and leave the query as it gets updated. Thanks to @stefek99 for the contribution!

You can check out a live demo of this example here.

This example is just a rules.json file which contains some security rules you can use for your GeoFire node. While this does help to enforce the schema of the data, it does not prevent a malicious user from scraping or overwriting your GeoFire data. You should replace all of the ".write" rules with some custom logic to restrict who can write to that node.

You can check out the example rules.json file here.

This is a fully-featured, complex example which combines GeoFire, Google Maps, and the Firebase Transit Open Data Set. Firebase provides a public Firebase which contains the realtime locations of public transit vehicles in several major US cities, including San Francisco MUNI. The data set also contains GeoFire data for each vehicle which we used to create this demo.

Drag around the purple circle to the left to see the vehicles which are currently within its radius. The results update in realtime as you move the circle and as vehicles travel around the city. GeoFire handles all of the hard work, telling you exactly when vehicles enter and exit the circle. It also selectively loads only the data geographically close to the circle, meaning GeoFire data for buses in New York or Chicago are not loaded into memory unnecessarily.

You can check out a live demo of this example here.