简体   繁体   English

我要全部检索经度和纬度为 1 公里的半径内的客户的所有数据

[英]I want all retrieve all data of customer within a radius with longtude and latitude of 1 km

I'm using redash and my table looks something like this.我正在使用 redash,我的表格看起来像这样。 I'm just learning sql. This is very advanced for me.我正在学习 sql。这对我来说非常先进。 I searched many questions, no queries worked for me我搜索了很多问题,但没有任何查询对我有用

|user_id | long | lat  |
|1       |31.000|26.000|
|2       |30.000|25,000|
|3       |30.003|25,007|

I need to get all the customers that used my service in this point and a radius of 1 km as well my table looks something like this one written above adding that point of user 1 is my cennter point我需要让所有在这一点上使用我的服务的客户和 1 公里的半径以及我的表看起来像上面写的那样添加用户 1 的点是我的中心点

It is hard task just because longitude 1 is the different number of kilometers on different areas(zero on pole, 111km on equator).这是一项艰巨的任务,因为经度 1 是不同地区的不同公里数(极点为零,赤道为 111 公里)。

So most likely you have first filter your data using some values in the range for your country, after that use some specialized library to calculate the exact distance.因此,很可能您首先使用您所在国家/地区范围内的一些值来过滤数据,然后使用一些专门的库来计算确切的距离。

If you have exact point before search, you have to如果你在搜索之前有确切的点,你必须

  1. Ask library outside MySQL what is distance 1km in longitude and latitude in the area问图书馆外面MySQL 1km在该地区的经纬度距离是多少
  2. Filter your dataset with pointX-deltaX,pointX-deltaX and pointY- deltaY, pointY+deltaY.使用 pointX-deltaX、pointX-deltaX 和 pointY-deltaY、pointY+deltaY 过滤数据集。 After this you will get square which contain your circle在此之后你会得到包含你的圆圈的正方形
  3. calculate distance via specialized library or using math formula to ensure it is circle.通过专门的库或使用数学公式计算距离以确保它是圆的。

you can use spatial functions你可以使用空间函数

SELECT 
    ppl.user_id,
    ST_DISTANCE_SPHERE(POINT(31.000, 26.000),
            POINT(ppl.Long, ppl.Lat))  AS distance
FROM
    `mtytable` AS ppl
WHERE
  user_id  > 1 
HAVING distance < 1000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用mariaDb,mySQL获取以km为单位的半径内的所有空间类型点 - get all spatial type points within radius in km with mariaDb, mySQL MySql性能查找1公里内的所有用户 - MySql performance find all users that are within 1 km 在给定位置(经度,纬度)的Y半径内找到X中的所有值 - Find all values from X within Y radius from a given location (longitude,latitude) 如何从给定半径内的数据库中检索经度和纬度? - How to retrieve Longitude and Latitude from database within a given radius? 我有包含纬度和经度等的表名,现在我想在 mysql 查询中获取半径中的数据? - I have table name with latitude and longitude and so on, now i want to get data with in radius in mysql query? 如何查询纬度/经度区域内的所有记录? - How can I query for all records within latitude / longitude area? 如何在MySql数据库中检索共享的所有行都在特定的半径范围内 - How to retrieve all rows thats co-ords are within a specifc radius in MySql Database 我想根据属性ID从上述4个表中检索所有数据 - i want to retrieve all data from the above 4 tables, based on property id 我想从MySQL数据库中检索去年的记录,但它正在从数据库中检索所有数据 - I want to retrieve last year record from MySQL database but it's retrieving all data's from database 算法/ MySQL - 获取半径内的所有点 - Algorithm / MySQL - Get all points within a radius
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM