<commit_before># GeoFire — Realtime location queries with Firebase

[![Build Status](https://travis-ci.org/firebase/geofire.svg)](https://travis-ci.org/firebase/geofire)
[![Version](https://badge.fury.io/gh/firebase%2Fgeofire.svg)](http://badge.fury.io/gh/firebase%2Fgeofire)

GeoFire is an open-source JavaScript library that allows you to store and query a set
of items based on their geographic location.

GeoFire uses [Firebase](https://www.firebase.com/) for data
storage, allowing query results to be updated in realtime as they change.
GeoFire does more than just measure the distance between locations; *it
selectively loads only the data near certain locations, keeping your
applications light and responsive*, even with extremely large datasets.

## Live Examples

To see GeoFire in action, you can [play around with our fully-featured demo](https://geofire.firebaseapp.com/sfVehicles/index.html). (Drag the purple circle!)
This demo maps all of the San Francisco MUNI vehicles within a certain search radius. You can
drag around the search radius and see the vehicles update in realtime.

[![SF MUNI Demo Image](./examples/sfVehicles/images/sf-vehicles.png)](https://geofire.firebaseapp.com/sfVehicles/index.html)

You can find a full list of our demos [here](https://geofire.firebaseapp.com/index.html)
and view the code for each of them in the [examples directory](./examples/) of this repository.
The examples cover some of the common use cases for GeoFire and explain how to protect your data
using security rules.

## Downloading GeoFire

In order to use GeoFire in your project, you need to include the following files in your HTML:

```html
<!-- RSVP -->
<script src="rsvp.min.js"></script>

<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script>

<!-- GeoFire -->
<script src="https://cdn.firebase.com/libs/geofire/2.1.0/geofire.min.js"></script>
```

Use the URL above to download both the minified and non-minifed versions of GeoFire from the Firebase CDN. You can also download them from the
`/dist/` directory of this GitHub repository. [Firebase](https://www.firebase.com/docs/web-quickstart.html)
and [RSVP](https://github.com/tildeio/rsvp.js/) can be downloaded directly from their respective websites.

You can also install GeoFire via npm or Bower and the dependencies will be downloaded automatically:

```bash
$ npm install geofire --save
```

```bash
$ bower install geofire --save
```

## Getting Started with Firebase

GeoFire requires Firebase in order to store location data. You can [sign up here](https://www.firebase.com/signup/) for a free account.

## API Reference

### GeoFire

A `GeoFire` instance is used to read and write geolocation data to your Firebase and to create queries.

#### new GeoFire(firebaseRef)

Creates and returns a new `GeoFire` instance to manage your location data. Data will stored at
the location pointed to by `firebaseRef`. Note that this `firebaseRef` can point to anywhere in your Firebase.

```JavaScript
// Create a Firebase reference where GeoFire will store its information
var firebaseRef = new Firebase("https://<my_firebase>.firebaseio.com/");

// Create a GeoFire index
var geoFire = new GeoFire(firebaseRef);
```

#### GeoFire.ref()

Returns the `Firebase` instance used to create this `GeoFire` instance.

```JavaScript
var firebaseRef = new Firebase("https://<my_firebase>.firebaseio.com/");
var geoFire = new GeoFire(firebaseRef);

var ref = geoFire.ref()  // ref === firebaseRef
```

#### GeoFire.set(key, location)

Adds the specified `key` - `location` pair to Firebase. If the provided `key`
already exists in this `GeoFire`, it will be overwritten with the new `location`
value. `location` must have the form `[latitude, longitude]`.

Returns a promise which is fulfilled when the new location has been synchronized with the Firebase servers.

`key` must be a string and a [valid Firebase key name](https://www.firebase.com/docs/creating-references.html)

```JavaScript
geoFire.set("some_key", [37.79, -122.41]).then(function() {
  console.log("Provided key has been added to GeoFire");
}, function(error) {
  console.log("Error: " + error);
});
```

#### GeoFire.get(key)

Fetches the location stored for `key`.

Returns a promise fulfilled with the `location` corresponding to the provided `key`.
If `key` does not exist, the returned promise is fulfilled with `null`.<commit_msg>Fixed code typo in README<commit_after># GeoFire — Realtime location queries with Firebase

[![Build Status](https://travis-ci.org/firebase/geofire.svg)](https://travis-ci.org/firebase/geofire)
[![Version](https://badge.fury.io/gh/firebase%2Fgeofire.svg)](http://badge.fury.io/gh/firebase%2Fgeofire)

GeoFire is an open-source JavaScript library that allows you to store and query a set
of items based on their geographic location.

GeoFire uses [Firebase](https://www.firebase.com/) for data
storage, allowing query results to be updated in realtime as they change.
GeoFire does more than just measure the distance between locations; *it
selectively loads only the data near certain locations, keeping your
applications light and responsive*, even with extremely large datasets.

## Live Examples

To see GeoFire in action, you can [play around with our fully-featured demo](https://geofire.firebaseapp.com/sfVehicles/index.html). (Drag the purple circle!)
This demo maps all of the San Francisco MUNI vehicles within a certain search radius. You can
drag around the search radius and see the vehicles update in realtime.

[![SF MUNI Demo Image](./examples/sfVehicles/images/sf-vehicles.png)](https://geofire.firebaseapp.com/sfVehicles/index.html)

You can find a full list of our demos [here](https://geofire.firebaseapp.com/index.html)
and view the code for each of them in the [examples directory](./examples/) of this repository.
The examples cover some of the common use cases for GeoFire and explain how to protect your data
using security rules.

## Downloading GeoFire

In order to use GeoFire in your project, you need to include the following files in your HTML:

```html
<!-- RSVP -->
<script src="rsvp.min.js"></script>

<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script>

<!-- GeoFire -->
<script src="https://cdn.firebase.com/libs/geofire/2.1.0/geofire.min.js"></script>
```

Use the URL above to download both the minified and non-minifed versions of GeoFire from the Firebase CDN. You can also download them from the
`/dist/` directory of this GitHub repository. [Firebase](https://www.firebase.com/docs/web-quickstart.html)
and [RSVP](https://github.com/tildeio/rsvp.js/) can be downloaded directly from their respective websites.

You can also install GeoFire via npm or Bower and the dependencies will be downloaded automatically:

```bash
$ npm install geofire --save
```

```bash
$ bower install geofire --save
```

## Getting Started with Firebase

GeoFire requires Firebase in order to store location data. You can [sign up here](https://www.firebase.com/signup/) for a free account.

## API Reference

### GeoFire

A `GeoFire` instance is used to read and write geolocation data to your Firebase and to create queries.

#### new GeoFire(firebaseRef)

Creates and returns a new `GeoFire` instance to manage your location data. Data will stored at
the location pointed to by `firebaseRef`. Note that this `firebaseRef` can point to anywhere in your Firebase.

```JavaScript
// Create a Firebase reference where GeoFire will store its information
var firebaseRef = new Firebase("https://<my_firebase>.firebaseio.com/");

// Create a GeoFire index
var geoFire = new GeoFire(firebaseRef);
```

#### GeoFire.ref()

Returns the `Firebase` instance used to create this `GeoFire` instance.

```JavaScript
var firebaseRef = new Firebase("https://<my_firebase>.firebaseio.com/");
var geoFire = new GeoFire(firebaseRef);

var ref = geoFire.ref();  // ref === firebaseRef
```

#### GeoFire.set(key, location)

Adds the specified `key` - `location` pair to Firebase. If the provided `key`
already exists in this `GeoFire`, it will be overwritten with the new `location`
value. `location` must have the form `[latitude, longitude]`.

Returns a promise which is fulfilled when the new location has been synchronized with the Firebase servers.

`key` must be a string and a [valid Firebase key name](https://www.firebase.com/docs/creating-references.html)

```JavaScript
geoFire.set("some_key", [37.79, -122.41]).then(function() {
  console.log("Provided key has been added to GeoFire");
}, function(error) {
  console.log("Error: " + error);
});
```

#### GeoFire.get(key)

Fetches the location stored for `key`.

Returns a promise fulfilled with the `location` corresponding to the provided `key`.
If `key` does not exist, the returned promise is fulfilled with `null`.
{'fraction_non_alphanumeric': 0.11284663271080927, 'fraction_numerical': 0.0040747028862478775, 'mean_word_length': 4.631612492033142, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 30, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4275337', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2578, 'n_words': 1023}