- // Other search uses the location_point and location_area tables
-
- // If we've not yet done the area search do it now
- if ($aArea === false)
- {
- $sSQL = 'select place_id,rank_address,ST_distance('.$sPointSQL.', centroid) as distance from location_area';
- $sSQL .= ' WHERE ST_Contains(area,'.$sPointSQL.') and rank_search <= '.$iMaxRank;
- $sSQL .= ' ORDER BY rank_address desc, ST_distance('.$sPointSQL.', centroid) ASC limit 1';
- $aArea = $oDB->getRow($sSQL);
- if ($aArea) $fMaxAreaDistance = $aArea['distance'];
- }
-
- // 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;
- }
- }