我正在從事一個項目,每個用戶都有自己的座標緯度/經度,從谷歌地理編碼器服務提取...如何定義lat/lng位置周圍的放射狀搜索區域?
現在我想實現搜索功能 - >你可以輸入半徑(公里)如果有人在半徑範圍內,該配置文件將彈出...
當搜索區域實際上是一個正方形時,它並不難以實現,但是如何獲得此功能以及如何使用作爲搜索區域圈?
這裏是代碼,來構建MySQL查詢的「搜索」部分:
// This is the location of the user who submitted the search function.
mysql_select_db("$db_profile");
$sql = "SELECT location_lat,
location_lng
FROM location
WHERE id = '$global_id'";
$sql = mysql_query($sql);
$row = mysql_fetch_array($sql);
// The coordinates of the user.
$lat = $row['location_lat'];
$lng = $row['location_lng'];
// the entered radius in kilometers - here it is converted to degree (1° = 111km).
$x_degree = $global_search_radius_value/111;
// define the search grid (it is a squere! but I want a circle!).
$lat_neg = $lat - $x_degree;
$lat_pos = $lat + $x_degree;
$lng_neg = $lng - $x_degree;
$lng_pos = $lng + $x_degree;
// build the search part of the mysql query
$heredoc_search_radius = <<<EOD
AND ($db_profile.location.location_lat > '$lat_neg'
AND $db_profile.location.location_lat < '$lat_pos'
AND $db_profile.location.location_lng > '$lng_neg'
AND $db_profile.location.location_lng < '$lng_pos')
EOD;
我該如何使用,而不是squere了一圈!?