K
K
kruteev2014-03-15 02:46:14
MySQL
kruteev, 2014-03-15 02:46:14

Mysql - how to select points within a radius of 10 kilometers using gps coordinates?

Good day. No matter how much the Internet was swarming, it was not possible to design a working solution.
The task is as follows: The mysql database has a table with points on the ground, each point, of course, has gps coordinates. How to extract points from the base within a radius of 10, for example, kilometers from the search point, the gps coordinates of which are also known?
For specific code examples, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Kokcuk, 2014-03-15
@kruteev

SELECT
    id, (
      3959 * acos (
      cos ( radians(60.0000) )
      * cos( radians( lat ) )
      * cos( radians( lng ) - radians(30.0000) )
      + sin ( radians(60.0000) )
      * sin( radians( lat ) )
    )
) AS distance
FROM markers
HAVING distance < 30
ORDER BY distance
LIMIT 0 , 20;

Something like this

A
afiskon, 2014-03-15
@afiskon

It seems to me that you have chosen the wrong DBMS for your tasks. PostgreSQL clicks things like nefig to do - there are special data types, indexes and so on. Here are some details on this.

O
OnYourLips, 2014-03-15
@OnYourLips

This is one of the few situations where stored functions will be useful. Do you know the Pythagorean theorem?

L
Liny_li, 2014-03-15
@Liny_li

Maybe this will work:
js-php.ru/web-development/distance-from-dot-to-dot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question