我有两个表如下所示:
tbl_properties和tbl_postcodes
它应列出所选邮政编码周围5公里的物业。
我试图得到下面的查询结果,但它没有得到正确的结果。
SELECT* FROM (
选择p.*,圆形(60 * 1.1515 * 1.609344*度(ACOS(COS(RADIANS(pc.纬度
))*COS(RADIANS(p.lat
))*COS(RADIANS(pc.经度
-p.lng
))SIN(RADIANS(pc.纬度
)*SIN(RADIANS(p.lng
)) ) ), 2)AS距离
AS p JOINpostcodes_geoAS pc ON(p.postcode_id
=pc.id
)
其中p.postcode_id IN(79279078612613))作为ftbl,其中距离
以下是提供基于邮政编码搜索所需相同功能的web服务。
http://www.geonames.org/export/web-services.html
在这里,您可以将邮编和半径作为参数传递,它将以XML和JSON格式返回与此相关的邮政编码列表。
例如:http://api.geonames.org/findNearbyPostalCodesJSON?postalcode=2032
@奎师那,你觉得怎么样
SELECT *
FROM (
SELECT properties.*
,(111.045000 * DEGREES(ACOS(COS(RADIANS(- 33.867487)) * COS(RADIANS(lat)) * COS(RADIANS(151.206990 - lng)) + SIN(RADIANS(- 33.867487)) * SIN(RADIANS(lat))))) AS distance
FROM `properties`
WHERE `properties`.`deleted_at` IS NULL
AND lat BETWEEN - 33.912514
AND - 33.822460
AND lng BETWEEN 151.152763
AND 151.261218
) AS properties
WHERE `properties`.`deleted_at` IS NULL
UNION
SELECT *
FROM (
SELECT properties.*
,(111.045000 * DEGREES(ACOS(COS(RADIANS(- 33.914437)) * COS(RADIANS(lat)) * COS(RADIANS(151.241642 - lng)) + SIN(RADIANS(- 33.914437)) * SIN(RADIANS(lat))))) AS distance
FROM `properties`
WHERE `properties`.`deleted_at` IS NULL
AND lat BETWEEN - 33.959464
AND - 33.869411
AND lng BETWEEN 151.187384
AND 151.295899
) AS properties
WHERE `properties`.`deleted_at` IS NULL
UNION
SELECT *
FROM (
SELECT properties.*
,(111.045000 * DEGREES(ACOS(COS(RADIANS(- 33.914437)) * COS(RADIANS(lat)) * COS(RADIANS(151.241642 - lng)) + SIN(RADIANS(- 33.914437)) * SIN(RADIANS(lat))))) AS distance
FROM `properties`
WHERE `properties`.`deleted_at` IS NULL
AND lat BETWEEN - 33.959464
AND - 33.869411
AND lng BETWEEN 151.187384
AND 151.295899
) AS properties
WHERE `properties`.`deleted_at` IS NULL Limit 10
,10
这可能会在您需要时对您有所帮助,但您需要做一些准备查询的工作