mollie - 10 months ago 45

JSON Question

I have a list of user's and their details stored in db with latitudes and longitudes. I need to make query,

When any single user want's to display how many user's available in nearest 200m from his position in Google map.

Plz tell me how's its possible to get all the user's name or total number of user in particular area.

Answer

I use this query to get the radius from lat long.

```
SELECT
*,
( 6371 * acos( cos( radians({$lat}) ) * cos( radians( `lat` ) ) * cos( radians( `lng` ) - radians({$lng}) ) + sin( radians({$lat}) ) * sin( radians( `lat` ) ) ) ) AS distance
FROM `positions`
HAVING distance <= {$radius}
ORDER BY distance ASC
```

6371 is the earth radius im km.

Source (Stackoverflow)