查找经纬度记录 [英] find records with latitude and longitude
问题描述
可能重复:
查找两个纬度/经度点之间距离的最快方法
Possible Duplicate:
Fastest Way to Find Distance Between Two Lat/Long Points
我有一个位置表,该表由所有位置及其纬度和经度值组成.我正在获取特定位置.登录.和半径.现在,我想查找该半径范围内和给定纬度内的所有回波.而且很长.价值观.我正在使用以下查询.但是我不确定它是否能给我正确的结果.
I have locations table which consists of all the locations with their latitude and longitude values. I am getting the particular locations lat. logn. and radius. Now, I want to find all the reocords within this radius and for that given lat. and long. values. I am using the following query. But I am not sure whether it gives me the correct results or not.
根据给定的经度和纬度,我发现lat.min和max为-
From given lat and long I am finding out lat.min and max as -
$lng_min = $longitude - $radius / abs(cos(deg2rad($latitude)) * 69);
$lng_max = $longitude + $radius / abs(cos(deg2rad($latitude)) * 69);
$lat_min = $latitude - ($radius / 69);
$lat_max = $latitude + ($radius / 69);
,然后使用以下查询-
SELECT * FROM merchant_branches,locations
where locations."coorX" BETWEEN $lng_min AND $lng_max
AND
locations."coorY" BETWEEN $lat_min AND $lat_max
and merchant_branches.location_id = locations.id
其中位置ID是商人_表中的外键.
where location id is the foreign key in merchant_brach table.
我对获得的结果感到困惑.请帮助我.
I am confused about the results I am getting. Plz help me.
推荐答案
您必须使用类似的方法才能将最接近的结果获取到给定位置
You have to use something like this to get the nearest results to a given location
$query = sprintf(
"SELECT foo,
6371 * ACOS( Cos(RADIANS(lat)) * COS(RADIANS(%f))
* COS(RADIANS(%f) - RADIANS(lng)) + SIN(RADIANS(lat))
* SIN(RADIANS(%f)) ) * 1000 AS distance
FROM `%s`
ORDER BY distance",
$lat, $lag, $lng, $table
);
您必须根据表结构设置$lat
,$lng
和$table
,并且可能会限制结果.
You have to set $lat
, $lng
and $table
according to your table structure and maybe set a limit to the result.
您可以在此处获得详细的移植信息使用MySQL进行地理距离搜索.
You get a detailed explantation here Geo Distance Search with MySQL.
这篇关于查找经纬度记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!