Skip to content

Instantly share code, notes, and snippets.

@rubemlrm
Created July 10, 2019 20:07
Show Gist options
  • Save rubemlrm/8962c470e228d5f838d943b80aeb0c20 to your computer and use it in GitHub Desktop.
Save rubemlrm/8962c470e228d5f838d943b80aeb0c20 to your computer and use it in GitHub Desktop.
GPS query
SELECT DISTINCT es.county_id, latitude , longitude,
IFNULL(tr_county_name.value,co.name) AS countyName,
es.name, co.name, co.code
FROM hi_establishments as es
LEFT JOIN hi_counties as co ON co.id = es.county_id
LEFT JOIN hi_translations AS tr_county_name ON tr_county_name.hi_table = 'hi_counties'
AND tr_county_name.lang = 'pt'
AND tr_county_name.field = 'name'
AND tr_county_name.row_id = co.id
WHERE valence_id = {$valenceID}
GROUP BY countyName
HAVING (
3959 * ACOS(
COS(
RADIANS(
{$userCoordinates["latitude"]})) * COS(RADIANS(latitude)) *
COS(RADIANS(longitude) - RADIANS({$userCoordinates["longitude"]})
)
+ SIN(RADIANS({$userCoordinates["latitude"]}))
* SIN(RADIANS(latitude)))) < 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment