A
A
Alexander2016-07-08 18:47:28
PHP
Alexander, 2016-07-08 18:47:28

How to select objects that are "closer than 500 meters" from a set of other objects?

Hello Toaster!
1. There is a mysql table with a set of points (lat, lng fields). This is how I store the coordinates of the Black Sea contour :)
2. There is a table with hotels (they also have lat and lng fields).
How can I select "all hotels located near the sea" with one request (from 0 to 1000 meters from the sea).
In Google I found an example of a query to search for "the nearest points relative to the current one":

SELECT id, ( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance 
FROM sea_latlng 
HAVING distance < 25 
ORDER BY distance

But it doesn't seem to suit me.
Tell me what is the best way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2016-07-08
@AMar4enko

Поискать библиотеки для работы с геоданными, который умеют работать с полигонами.
Один раз прогнать все отели, посчитав удаленность каждого, записать в базу в отдельное поле. Фильтровать по нему.

D
Dimonchik, 2016-07-08
@dimonchik2013

postgis.net

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question