Answer the question
In order to leave comments, you need to log in
Algorithm for obtaining a square by coordinates?
The essence of the question is, we have an array of coordinate points (the user's route in the format Point (lat, lng)), and we need to take the saved points from the database that lie not far from our route (conditionally 100m).
points in the database have fields (lat,lng, name...).
To pick up points close to one is not a problem did so (
"SELECT
*,
(
6371 *
acos(cos(radians($lat)) *
cos(radians(dots.lat)) *
cos(radians(dots.lng) -
radians($lng)) +
sin(radians($lat)) *
sin(radians(dots.lat)))
) AS distance,
FROM dots
HAVING distance < 0.1
ORDER BY distance LIMIT 0, 20
;"
Answer the question
In order to leave comments, you need to log in
Sergey Sokolov , in short, he seems to have done it))
SET @home = ST_GeomFromText('LINESTRING(
//Список наших точек через которые идет маршрут
53.862263 27.483486,
53.871521 27.493636,
53.875594 27.496447,
53.880938 27.500744,
53.882699 27.505121,
53.884246 27.504435,
53.891446 27.500293,
53.896630 27.497375,
53.905348 27.496302,
53.912531 27.495487,
53.918726 27.496882)');
SELECT *, ST_AsText(geo) as Coord,
// Дистанция считается странно получается вроде правильно , но не уверен насчет точности .
// В оригинале в доках написано умножать ее на .001 для км и .00067... для миль
// но у меня так не работало и показывало до объекта 0,003км хотя по факту до него 300м вот я решил
умножать ее на 100 (хотя хз может оно там сантиметрах считает)
ST_DISTANCE(@home, geo) * 100 AS dist
FROM dots
// дистанция от маршрута в радиусе которой нам нужны точки (в км )
HAVING dist < 1
ORDER BY dist
LIMIT 30
I would process line segments (pairs of points), and use the formula for the distance from a point to a line plus the projection of a point onto a line to understand whether the point is near the middle of the line or near the ends.
Don't want to use MySQL's spatial data capabilities? See feature list .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question