到目前为止,我的代码如下:
static function get_parties_zipcode_and_radius($ZIPCODE_, $RADIUS_)
{
// get coordinates
$google_json = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=" . $ZIPCODE_ . "&sensor=false"), true);
$lat = $google_json["results"][0]["geometry"]["location"]["lat"];
$lng = $google_json["results"][0]["geometry"]["location"]["lng"];
// query coordinates
$query = "SELECT ID, ( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) )
* cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin(radians(lat)) ) ) AS distance
FROM PARTIES
HAVING distance < 25
ORDER BY distance
LIMIT 0 , 20;";
$db = $GLOBALS['DB']->query($query);
$db->execute();
$db->bind_result($ID);
$result = array();
while ($db->fetch())
{
array_push($result, $ID);
}
$db->close();
return $result;
}
我收到错误:
Fatal error: Uncaught Error: Call to a member function execute() on boolean in /var/www/html/Party/lib/Party.php:244 Stack trace: #0 /var/www/html/Party/lib/Party.php(256): Party::get_parties_zipcode_and_radius('98683', '3') #1 {main} thrown in /var/www/html/Party/lib/Party.php on line 244
我从这里获得了基于坐标查询数据库的代码:MySQL Great Circle Distance (Haversine formula)
我无法将其整合到mysqli格式中。我更习惯于已经折旧的旧版mysql,我不确定如何转换。应该是一个直接的解决方案,我认为。