public function findDistance(Query $query, array $options) {
		$options += ['tableName' => null, 'sort' => true];
		$sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);

		if ($query->autoFields() === null) {
			$query->autoFields(true);
		}

		$query->select(['distance' => $query->newExpr($sql)]);
		if (isset($options['distance'])) {
			// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
			$query->where(function ($exp) use ($sql, $options) {
				return $exp->lt($sql, $options['distance']);
			});
		}

		if ($options['sort']) {
			$sort = $options['sort'] === true ? 'ASC' : $options['sort'];
			$query->order(['distance' => $sort]);
		}

		return $query;
	}