我想从坐标(lat / lng)搜索最近的位置到mysql数据库,我使用球面的余弦法来搜索这些地方:
SELECT onlycoord.id, locations.name, locations.ascii,
locations.latitude, locations.longitude,
locations.country, locations.elevation,
locations.gtopo30, locations.timezone,
(6371 * ACOS(
COS( RADIANS( 48.48 ) ) *
COS( RADIANS( onlycoord.latitude ) ) *
COS(
RADIANS( onlycoord.longitude ) -
RADIANS( 2.20 )
) +
SIN( RADIANS( 48.48 ) ) *
SIN( RADIANS( onlycoord.latitude ) )
)) AS distance
FROM onlycoord USE INDEX (coordinate)
LEFT JOIN locations USE INDEX (id)
ON (onlycoord.id = locations.id)
WHERE onlycoord.latitude BETWEEN (
48.48 - ( 5 / 111 )
) AND (
48.48 + ( 5 / 111 )
) AND onlycoord.longitude BETWEEN (
2.20 - ( 5 / ABS( COS(
RADIANS( 48.48 )
) * 111 ) )
) AND (
2.20 + ( 5 / ABS( COS(
RADIANS( 48.48 )
) * 111 ) )
)
ORDER BY distance ASC
LIMIT 0, 20
当6371是地球半径(km)时,111(km)是1°纬度,cos(纬度)* 111(km)是经度1°,5(km)是搜索半径。
问题:我想要找到至少8个城市,但半径5公里很小但是对于精简区域(许多城市)来说很快,所以如果我使用search radius
对于精简区域来说太大,查询速度很慢(许多结果:order by),但对于非精简,search radius
太小,无法找到至少8个城市......
如果找到的城市的数量search radius
(x2)的递归查询? 8(仅使用mysql)?
由于