public static function GeometryProximityTrait::getGeometryProximityQueryFragment in Geolocation Field 8.3
Gets the query fragment for adding a proximity field to a query.
Parameters
string $table_name: The proximity table name.
string $field_id: The proximity field ID.
string $filter_lat: The latitude to filter for.
string $filter_lng: The longitude to filter for.
Return value
string The fragment to enter to actual query.
3 calls to GeometryProximityTrait::getGeometryProximityQueryFragment()
- GeoProximityArgument::getFormula in modules/
geolocation_geometry/ src/ Plugin/ views/ argument/ GeoProximityArgument.php - Get the formula for this argument.
- GeoProximityField::query in modules/
geolocation_geometry/ src/ Plugin/ views/ field/ GeoProximityField.php - Called to add the field to a query.
- GeoProximityFilter::query in modules/
geolocation_geometry/ src/ Plugin/ views/ filter/ GeoProximityFilter.php - Add this filter to the query.
File
- modules/
geolocation_geometry/ src/ GeometryProximityTrait.php, line 25
Class
- GeometryProximityTrait
- Trait GeometryProximityTrait.
Namespace
Drupal\geolocation_geometryCode
public static function getGeometryProximityQueryFragment($table_name, $field_id, $filter_lat, $filter_lng) {
// Define the field name.
$field_point = "{$table_name}.{$field_id}_geometry";
// deg2rad() is sensitive to empty strings. Replace with integer zero.
$filter_lat = empty($filter_lat) ? '0' : $filter_lat;
$filter_lng = empty($filter_lng) ? '0' : $filter_lng;
return 'ST_Distance_Sphere(ST_GeomFromText(\'POINT(' . $filter_lng . ' ' . $filter_lat . ')\'), ST_GeomFromText(CONCAT(\'POINT(\', ST_Y(' . $field_point . '), \' \', ST_X(' . $field_point . '), \')\')))/1000';
}