【发布时间】:2012-01-16 11:37:20
【问题描述】:
我正在做一个项目,每个用户都有自己的坐标 lat / lng,从谷歌地理编码器服务中提取...
现在我想实现一个搜索功能 -> 你可以输入半径(km),如果有人在半径内,就会弹出个人资料...
当搜索区域实际上是一个正方形时,让它工作并不难,但是我如何让它工作,用一个圆圈作为搜索区域?
这是构建 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;
如何使用圆形而不是方形!?
【问题讨论】:
标签: php mysql google-maps google-maps-api-3