private _updateLocation()

in packages/geofire/src/GeoQuery.ts [557:584]


  private _updateLocation(key: string, location?: Geopoint): void {
    validateLocation(location);
    // Get the key and location
    let distanceFromCenter: number, isInQuery;
    const wasInQuery: boolean = (key in this._locationsTracked) ? this._locationsTracked[key].isInQuery : false;
    const oldLocation: number[] = (key in this._locationsTracked) ? this._locationsTracked[key].location : null;

    // Determine if the location is within this query
    distanceFromCenter = distanceBetween(location, this._center);
    isInQuery = (distanceFromCenter <= this._radius);

    // Add this location to the locations queried dictionary even if it is not within this query
    this._locationsTracked[key] = {
      location,
      distanceFromCenter,
      isInQuery,
      geohash: geohashForLocation(location)
    };

    // Fire the 'key_entered' event if the provided key has entered this query
    if (isInQuery && !wasInQuery) {
      this._fireCallbacksForKey('key_entered', key, location, distanceFromCenter);
    } else if (isInQuery && oldLocation !== null && (location[0] !== oldLocation[0] || location[1] !== oldLocation[1])) {
      this._fireCallbacksForKey('key_moved', key, location, distanceFromCenter);
    } else if (!isInQuery && wasInQuery) {
      this._fireCallbacksForKey('key_exited', key, location, distanceFromCenter);
    }
  }