- // Different search depending if we found an area match
- if ($aArea)
- {
- // Found best match area - is there a better point match?
- $sSQL = 'select place_id from location_point_'.($iMaxRank+1);
- $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.') ';
- $sSQL .= ' and rank_search > '.($aArea['rank_address']+3);
- $sSQL .= ' ORDER BY rank_address desc, ST_distance('.$sPointSQL.', centroid) ASC limit 1';
- $iPlaceID = $oDB->getOne($sSQL);
- if (PEAR::IsError($iPlaceID))
- {
- var_Dump($sSQL, $iPlaceID);
- exit;
- }
- }
- else
- {
- $sSQL = 'select place_id from location_point_'.($iMaxRank+1);
- $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.') ';
- $sSQL .= ' ORDER BY rank_address desc, ST_distance('.$sPointSQL.', centroid) ASC limit 1';
- $iPlaceID = $oDB->getOne($sSQL);
- if (PEAR::IsError($iPlaceID))
- {
- var_Dump($sSQL, $iPlaceID);
- exit;
- }
- }
- }
- }
- if (!$iPlaceID && $aArea) $iPlaceID = $aArea['place_id'];