protected $aExcludePlaceIDs = array();
protected $bDeDupe = true;
- protected $bReverseInPlan = false;
+ protected $bReverseInPlan = true;
protected $iLimit = 20;
protected $iFinalLimit = 10;
$this->aViewBox = array($fLeft, $fBottom, $fRight, $fTop);
}
+ function getViewBoxString()
+ {
+ if (!$this->aViewBox) return null;
+ return $this->aViewBox[0].','.$this->aViewBox[3].','.$this->aViewBox[2].','.$this->aViewBox[1];
+ }
+
function setRoute($aRoutePoints)
{
$this->aRoutePoints = $aRoutePoints;
function getDetails($aPlaceIDs, $iMinAddressRank = 0, $iMaxAddressRank = 30, $aAddressRankList = false, $sAllowedTypesSQLList = false, $bDeDupe = false)
{
+ if (sizeof($aPlaceIDs) == 0) return array();
+
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
// Get the details for display (is this a redundant extra step?)
$sCountryCodesSQL = false;
if ($this->aCountryCodes && sizeof($this->aCountryCodes))
{
- $sCountryCodesSQL = join(',', $this->aCountryCodes);
+ $sCountryCodesSQL = join(',', array_map('addQuotes', $this->aCountryCodes));
}
// Hack to make it handle "new york, ny" (and variants) correctly
$sViewboxSmallSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$this->aViewBox[0].",".(float)$this->aViewBox[1]."),ST_Point(".(float)$this->aViewBox[2].",".(float)$this->aViewBox[3].")),4326)";
$sViewboxLargeSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$aBigViewBox[0].",".(float)$aBigViewBox[1]."),ST_Point(".(float)$aBigViewBox[2].",".(float)$aBigViewBox[3].")),4326)";
- $bBoundingBoxSearch = true;
+ $bBoundingBoxSearch = $this->bBoundedSearch;
}
// Route SQL
failInternalError("Could not get large viewbox.", $sSQL, $sViewboxLargeSQL);
}
$sViewboxLargeSQL = "'".$sViewboxLargeSQL."'::geometry";
- $bBoundingBoxSearch = true;
+ $bBoundingBoxSearch = $this->bBoundedSearch;
}
// Do we have anything that looks like a lat/lon pair?
}
$aSearchResults = array();
- if ($sQuery || $aStructuredQuery)
+ if ($sQuery || $this->aStructuredQuery)
{
// Start with a blank search
$aSearches = array(
// Commas are used to reduce the search space by indicating where phrases split
if ($this->aStructuredQuery)
{
- $aPhrases = $aStructuredQuery;
+ $aPhrases = $this->aStructuredQuery;
$bStructuredPhrases = true;
}
else
if (CONST_Debug) { echo "<hr><b>Search Loop, group $iGroupLoop, loop $iQueryLoop</b>"; }
if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
- // Must have a location term
+ // No location term?
if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['fLon'])
{
if ($aSearch['sCountryCode'] && !$aSearch['sClass'] && !$aSearch['sHouseNumber'])
{
+ // Just looking for a country by code - look it up
if (4 >= $this->iMinAddressRank && 4 <= $this->iMaxAddressRank)
{
$sSQL = "select place_id from placex where calculated_country_code='".$aSearch['sCountryCode']."' and rank_search = 4";
$sSQL = "select place_id from placex where place_id in (".join(',',$aResultPlaceIDs).") ";
$sSQL .= "and (placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
- if ($aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$aAddressRankList).")";
+ if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$this->aAddressRankList).")";
$sSQL .= ") UNION select place_id from location_property_tiger where place_id in (".join(',',$aResultPlaceIDs).") ";
$sSQL .= "and (30 between $this->iMinAddressRank and $this->iMaxAddressRank ";
- if ($aAddressRankList) $sSQL .= " OR 30 in (".join(',',$aAddressRankList).")";
+ if ($this->aAddressRankList) $sSQL .= " OR 30 in (".join(',',$this->aAddressRankList).")";
$sSQL .= ")";
if (CONST_Debug) var_dump($sSQL);
$aResultPlaceIDs = $this->oDB->getCol($sSQL);
{
// Just interpret as a reverse geocode
$iPlaceID = geocodeReverse((float)$this->aNearPoint[0], (float)$this->aNearPoint[1]);
- $aSearchResults = $this->getDetails(array($iPlaceID));
+ if ($iPlaceID)
+ $aSearchResults = $this->getDetails(array($iPlaceID));
+ else
+ $aSearchResults = array();
}
// No results? Done
$aResult['lat'] = $aPointPolygon['centrelat'];
$aResult['lon'] = $aPointPolygon['centrelon'];
}
+
if ($this->bIncludePolygonAsPoints)
{
// Translate geometary string to point array
$aResult['icon'] = CONST_Website_BaseURL.'images/mapicons/'.$aClassType[$aResult['class'].':'.$aResult['type']]['icon'].'.p.20.png';
}
- if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['label'])
+ if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label'])
+ && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label'])
+ {
+ $aResult['label'] = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label'];
+ }
+ elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['label'])
&& $aClassType[$aResult['class'].':'.$aResult['type']]['label'])
{
$aResult['label'] = $aClassType[$aResult['class'].':'.$aResult['type']]['label'];