private function _searchLocation (ElementQuery $query, $value, $table)
	{
		$location = $value['location'];
		$country  = $value['country'] ?? null;
		$radius   = $value['radius'] ?? 50.0;
		$unit     = $value['unit'] ?? 'km';

		// Normalize location
		if (is_string($location))
			$location = GeoService::latLngFromAddress($location, $country);
		else if ($location instanceof Map)
			$location = ['lat' => $location->lat, 'lng' => $location->lng];
		else if (!is_array($location) || !isset($location['lat'], $location['lng']))
			$location = null;

		if ($location === null)
			return false;

		$lat = $location['lat'];
		$lng = $location['lng'];

		// Normalize radius
		if (!is_numeric($radius))
			$radius = (float) $radius;

		if (!is_numeric($radius))
			$radius = 50.0;

		// Normalize unit
		if ($unit === 'miles') $unit = 'mi';
		else if ($unit === 'kilometers') $unit = 'km';
		else if (!in_array($unit, ['mi', 'km'])) $unit = 'km';

		// Base Distance
		$distance = $unit === 'km' ? '111.045' : '69.0';

		// Store for populating search result distance
		$this->_location = $location;
		$this->_distance = (float) $distance;

		// Search Query
		$search = str_replace(["\r", "\n", "\t"], '', "(
			$distance *
			DEGREES(
				ACOS(
					COS(RADIANS($lat)) *
					COS(RADIANS([[$table.lat]])) *
					COS(RADIANS($lng) - RADIANS([[$table.lng]])) +
					SIN(RADIANS($lat)) *
					SIN(RADIANS([[$table.lat]]))
				)
			)
		)");

		// Restrict the results
		$restrict = [
			'and',
			[
				'and',
				"[[$table.lat]] >= $lat - ($radius / $distance)",
				"[[$table.lat]] <= $lat + ($radius / $distance)",
			],
			[
				'and',
				"[[$table.lng]] >= $lng - ($radius / ($distance * COS(RADIANS($lat))))",
				"[[$table.lng]] <= $lng + ($radius / ($distance * COS(RADIANS($lat))))",
			]
		];

		// Filter the query
		$query
			->subQuery
			->andWhere($restrict)
			->andWhere($search . ' <= ' . $radius);

		return $search;
	}
private function _searchLocation (ElementQuery $query, $value, $table)
	{
		$location = $value['location'];
		$country  = $value['country'] ?? null;
		$radius   = $value['radius'] ?? 50.0;
		$unit     = $value['unit'] ?? 'km';

		// Normalize location
		if (is_string($location))
			$location = GeoService::latLngFromAddress($location, $country);
		else if ($location instanceof Map)
			$location = ['lat' => $location->lat, 'lng' => $location->lng];
		else if (!is_array($location) || !isset($location['lat'], $location['lng']))
			$location = null;

		if ($location === null)
			return false;

		$lat = $location['lat'];
		$lng = $location['lng'];

		// Normalize radius
		if (!is_numeric($radius))
			$radius = (float) $radius;

		if (!is_numeric($radius))
			$radius = 50.0;

		// Normalize unit
		if ($unit === 'miles') $unit = 'mi';
		else if ($unit === 'kilometers') $unit = 'km';
		else if (!in_array($unit, ['mi', 'km'])) $unit = 'km';

		// Base Distance
		$distance = $unit === 'km' ? '111.045' : '69.0';

		// Store for populating search result distance
		$this->_location = $location;
		$this->_distance = (float) $distance;

		// Search Query
		$search = str_replace(["\r", "\n", "\t"], '', "(
			$distance *
			DEGREES(
				ACOS(
					COS(RADIANS($lat)) *
					COS(RADIANS([[$table.lat]])) *
					COS(RADIANS($lng) - RADIANS([[$table.lng]])) +
					SIN(RADIANS($lat)) *
					SIN(RADIANS([[$table.lat]]))
				)
			)
		)");

		// Restrict the results
		$restrict = [
			'and',
			[
				'and',
				"[[$table.lat]] >= $lat - ($radius / $distance)",
				"[[$table.lat]] <= $lat + ($radius / $distance)",
			],
			[
				'and',
				"[[$table.lng]] >= $lng - ($radius / ($distance * COS(RADIANS($lat))))",
				"[[$table.lng]] <= $lng + ($radius / ($distance * COS(RADIANS($lat))))",
			]
		];

		// Filter the query
		$query
			->subQuery
			->andWhere($restrict)
			->andWhere($search . ' <= ' . $radius);

		return $search;
	}
private function _searchLocation ( ElementQuery $ query , $ value , $ table ) { $ location = $ value [ 'location' ] ; $ country = $ value [ 'country' ] ?? null ; $ radius = $ value [ 'radius' ] ?? 50.0 ; $ unit = $ value [ 'unit' ] ?? 'km' ; // Normalize location if ( is_string ( $ location ) ) $ location = GeoService :: latLngFromAddress ( $ location , $ country ) ; else if ( $ location instanceof Map ) $ location = [ 'lat' => $ location -> lat , 'lng' => $ location -> lng ] ; else if ( ! is_array ( $ location ) || ! isset ( $ location [ 'lat' ] , $ location [ 'lng' ] ) ) $ location = null ; if ( $ location === null ) return false ; $ lat = $ location [ 'lat' ] ; $ lng = $ location [ 'lng' ] ; // Normalize radius if ( ! is_numeric ( $ radius ) ) $ radius = ( float ) $ radius ; if ( ! is_numeric ( $ radius ) ) $ radius = 50.0 ; // Normalize unit if ( $ unit === 'miles' ) $ unit = 'mi' ; else if ( $ unit === 'kilometers' ) $ unit = 'km' ; else if ( ! in_array ( $ unit , [ 'mi' , 'km' ] ) ) $ unit = 'km' ; // Base Distance $ distance = $ unit === 'km' ? '111.045' : '69.0' ; // Store for populating search result distance $ this -> _location = $ location ; $ this -> _distance = ( float ) $ distance ; // Search Query $ search = str_replace ( [ "\r" , "\n" , "\t" ] , '' , "(
			$distance *
			DEGREES(
				ACOS(
					COS(RADIANS($lat)) *
					COS(RADIANS([[$table.lat]])) *
					COS(RADIANS($lng) - RADIANS([[$table.lng]])) +
					SIN(RADIANS($lat)) *
					SIN(RADIANS([[$table.lat]]))
				)
			)
		)" ) ; // Restrict the results $ restrict = [ 'and' , [ 'and' , "[[$table.lat]] >= $lat - ($radius / $distance)" , "[[$table.lat]] <= $lat + ($radius / $distance)" , ] , [ 'and' , "[[$table.lng]] >= $lng - ($radius / ($distance * COS(RADIANS($lat))))" , "[[$table.lng]] <= $lng + ($radius / ($distance * COS(RADIANS($lat))))" , ] ] ; // Filter the query $ query -> subQuery -> andWhere ( $ restrict ) -> andWhere ( $ search . ' <= ' . $ radius ) ; return $ search ; }
Filters the query by location.

Returns either `false` if we can't filter by location, or the location
search string if we can.

@param ElementQuery $query
@param mixed        $value
@param string       $table

@return bool|string
@throws \yii\db\Exception
Filters the query by location .