- }
-
- // Only street found? In the US we can check TIGER data for nearest housenumber
- if (CONST_Use_US_Tiger_Data && $bIsTigerStreet && $this->iMaxRank >= 28) {
- $fSearchDiam = $aPlace['rank_search'] > 28 ? $aPlace['distance'] : 0.001;
- $sSQL = 'SELECT place_id,parent_place_id,30 as rank_search,';
- $sSQL .= 'ST_LineLocatePoint(linegeo,'.$sPointSQL.') as fraction,';
- $sSQL .= 'ST_distance('.$sPointSQL.', linegeo) as distance,';
- $sSQL .= 'startnumber,endnumber,interpolationtype';
- $sSQL .= ' FROM location_property_tiger WHERE parent_place_id = '.$oResult->iId;
- $sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')';
- $sSQL .= ' ORDER BY distance ASC limit 1';
-
- if (CONST_Debug) var_dump($sSQL);
-
- $aPlaceTiger = chksql(
- $this->oDB->getRow($sSQL),
- 'Could not determine closest Tiger place.'
- );
- if ($aPlaceTiger) {
- if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger);
- $aPlace = $aPlaceTiger;
- $oResult = new Result($aPlace['place_id'], Result::TABLE_TIGER);
- $oResult->iHouseNumber = closestHouseNumber($aPlaceTiger);
- $iParentPlaceID = $aPlace['parent_place_id'];
- $iMaxRank = 30;
- }
- }
-
- // The point we found might be too small - use the address to find what it is a child of
- if ($oResult !== null && $iMaxRank < 28) {
- if ($aPlace['rank_search'] > 28 && $iParentPlaceID) {
- $iPlaceID = $iParentPlaceID;
- } else {
- $iPlaceID = $oResult->iId;
- }
- $sSQL = 'select coalesce(p.linked_place_id, a.address_place_id)';
- $sSQL .= ' FROM place_addressline a, placex p';
- $sSQL .= " WHERE a.place_id = $iPlaceID and a.place_id = p.place_id";
- $sSQL .= " ORDER BY abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc";
- $sSQL .= ' LIMIT 1';
- $iPlaceID = chksql($this->oDB->getOne($sSQL), 'Could not get parent for place.');
- if ($iPlaceID) {
- $oResult = new Result($iPlaceID);
- }
- }
-