I have a mySql table named tbl_places
This contains fields Place_id
, PlaceName
, Place_LATITUDE
, place_LONGITUDE
.
I want to use it in the place detail
page now If the current place_id
of the open page is 4 then I want a maximum 6 records nearest to that place.
Suppose the current place is:
place_id = 4
place_name = Lal Killa
place_LATITUDE = 77.2413969039917
place_LONGITUDE = 28.653838307772872
I can't understand how to find nearest place to the current place??
Use below query:
SELECT
Place_id,
PlaceName,
(
3959
* acos(
cos( radians(37) )
* cos( radians( Place_LATITUDE ) )
* cos( radians( Place_LONGITUDE ) - radians(-122) )
+ sin( radians(37) )
* sin( radians( Place_LATITUDE ) )
)
) AS distance
FROM tbl_places
HAVING distance < 25
ORDER BY distance
LIMIT 0 , 20;
NOTE - Here latitude = 37 & longitude = -122
Also, check here for more reference.
You can use a Cohen–Sutherland (point clipping) algorithm to know the people near by, if you want to minimize the result,set it as a incremental order from 0 to YOUR_LIMIT.
it is better than a formula that convert a polar co-ordinates[(ie)lat and long] to XY
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.