1

I am developing a server on node.js. I need to find incoming users within the store in latitude and longitude.

I have a table of stores:

merchant_id |  merchant_name | ... |          locations        |
----------------------------------------------------------------
      1     |      name 1    | ... | (35.2400874,-80.8438284) |
      1     |      name 1    | ... | (35.2810371,-80.8285142) |
      2     |      name 2    | ... | (35.2810371,-80.8285142) |
      3     |      name 3    | ... | (35.2879564,-80.7948781) |

I also have a user table:

   usaer_id |    user_name   | ... |          locations        |
----------------------------------------------------------------
      1     |      name 1    | ... | (35.2358578,-80.8468168)  |
      1     |      name 1    | ... | (35.2366682,-80.8489705)  |
      2     |      name 2    | ... | (35.2433762,-80.8478121)  |
      3     |      name 3    | ... | (35.2632458,-80.8619878)  |
      4     |      name 4    | ... | (35.2778369,-80.8315268) |

Field types:

CREATE TABLE merchants(
    merchant_id                         SERIAL PRIMARY KEY, 
    merchant_name                       VARCHAR(220) NOT NULL, 
    ...
    location                            POINT
);

CREATE TABLE users(
    user_id                             SERIAL PRIMARY KEY, 
    user_name                           VARCHAR(40) NOT NULL, 
    ...
    notification                        POINT
);

How can I find users who are located within a radius of 3 kilometers from the store?

MegaRoks
  • 898
  • 2
  • 13
  • 30
  • 2
    Have a look at this https://stackoverflow.com/questions/36358188/most-efficient-way-to-find-points-within-a-certain-radius-from-a-given-point – Pavel Smirnov Mar 27 '19 at 09:11
  • 1
    Please consider using PostGIS, so a `geometry(point)` instead of `point`. – JGH Mar 27 '19 at 11:43

0 Answers0