Answer the question
In order to leave comments, you need to log in
How to get information within a certain radius?
Good afternoon!
How to get information within a certain radius?
Or how to sort "near me"?
I have a query like this:
SELECT DISTINCT name,
id, (
6371 * acos (
cos ( radians(43.639955) )
* cos( radians( coords_latitude ) )
* cos( radians( coords_longitude ) - radians(68.324195) )
+ sin ( radians(43.639955) )
* sin( radians( coords_latitude ) )
)
) AS distance
FROM areas
# HAVING distance < 10
ORDER BY distance
LIMIT 0 ,10
Answer the question
In order to leave comments, you need to log in
On your question, you can of course disassemble the models, nothing complicated. But in such cases, I usually do two subqueries. First I pull out an array with the required calculation. With the second request, I pull out the necessary models.
It is not clear what you mean by what needs to be implemented in Yii2. Run a simple query -
Yii::$app->db->createCommand($sql)->queryAll() - will return you the result of the query.
For reference:
1) use the point data type, mysql has GIS functions for that. And they are easier to use.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question