diff --git a/lib/Geocode.php b/lib/Geocode.php index 2d246d98..ce77862b 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -1698,10 +1698,11 @@ { // Just interpret as a reverse geocode $oReverse = new ReverseGeocode($this->oDB); - $oReverse->setLatLon((float)$this->aNearPoint[0], (float)$this->aNearPoint[1]); $oReverse->setZoom(18); - $aLookup = $oReverse->lookup(false); + $aLookup = $oReverse->lookup((float)$this->aNearPoint[0], + (float)$this->aNearPoint[1], + false); if (CONST_Debug) var_dump("Reverse search", $aLookup); diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 0c684a4e..6a531ebb 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -2,42 +2,14 @@ class ReverseGeocode { protected $oDB; - - protected $fLat; - protected $fLon; protected $iMaxRank = 28; - protected $aLangPrefOrder = array(); - - protected $bIncludePolygonAsPoints = false; - protected $bIncludePolygonAsText = false; - protected $bIncludePolygonAsGeoJSON = false; - protected $bIncludePolygonAsKML = false; - protected $bIncludePolygonAsSVG = false; - protected $fPolygonSimplificationThreshold = 0.0; - function ReverseGeocode(&$oDB) { $this->oDB =& $oDB; } - function setLanguagePreference($aLangPref) - { - $this->aLangPrefOrder = $aLangPref; - } - - function setLatLon($fLat, $fLon) - { - $this->fLat = (float)$fLat; - $this->fLon = (float)$fLon; - } - - function setRank($iRank) - { - $this->iMaxRank = $iRank; - } - function setZoom($iZoom) { // Zoom to rank, this could probably be calculated but a lookup gives fine control @@ -66,51 +38,11 @@ $this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28; } - function setIncludePolygonAsPoints($b = true) - { - $this->bIncludePolygonAsPoints = $b; - } - - function getIncludePolygonAsPoints() - { - return $this->bIncludePolygonAsPoints; - } - - function setIncludePolygonAsText($b = true) - { - $this->bIncludePolygonAsText = $b; - } - - function getIncludePolygonAsText() - { - return $this->bIncludePolygonAsText; - } - - function setIncludePolygonAsGeoJSON($b = true) - { - $this->bIncludePolygonAsGeoJSON = $b; - } - - function setIncludePolygonAsKML($b = true) - { - $this->bIncludePolygonAsKML = $b; - } - - function setIncludePolygonAsSVG($b = true) - { - $this->bIncludePolygonAsSVG = $b; - } - - function setPolygonSimplificationThreshold($f) - { - $this->fPolygonSimplificationThreshold = $f; - } - // returns { place_id =>, type => '(osm|tiger)' } // fails if no place was found - function lookup($bDoInterpolation = true) + function lookup($fLat, $fLon, $bDoInterpolation = true) { - $sPointSQL = 'ST_SetSRID(ST_Point('.$this->fLon.','.$this->fLat.'),4326)'; + $sPointSQL = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)'; $iMaxRank = $this->iMaxRank; $iMaxRank_orig = $this->iMaxRank; diff --git a/utils/warm.php b/utils/warm.php index 72eac27a..b034fa8c 100755 --- a/utils/warm.php +++ b/utils/warm.php @@ -27,7 +27,10 @@ if (!$aResult['search-only']) { $oReverseGeocode = new ReverseGeocode($oDB); - $oReverseGeocode->setIncludeAddressDetails(true); + $oReverseGeocode->setZoom(20); + $oPlaceLookup = new PlaceLookup($oDB); + $oPlaceLookup->setIncludeAddressDetails(true); + $oPlaceLookup->setLanguagePreference(array('en')); echo "Warm reverse: "; if ($bVerbose) echo "\n"; @@ -35,11 +38,12 @@ $fLat = rand(-9000, 9000) / 100; $fLon = rand(-18000, 18000) / 100; if ($bVerbose) echo "$fLat, $fLon = "; - $oReverseGeocode->setLanguagePreference(array('en')); - $oReverseGeocode->setLatLon($fLat, $fLon); - $oReverseGeocode->setZoom(20); - $aDetails = $oReverseGeocode->lookup(); - if ($bVerbose) echo $aDetails['langaddress']."\n"; + $aLookup = $oReverseGeocode->lookup($fLat, $fLon); + if ($aLookup && $aLookup['place_id']) + { + $aDetails = $oPlaceLookup->lookupPlace($aLookup); + if ($bVerbose) echo $aDetails['langaddress']."\n"; + } else echo "."; } echo "\n"; diff --git a/website/reverse.php b/website/reverse.php index 0e0f2ff8..07ef2d74 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -54,12 +54,9 @@ else if ($fLat !== false && $fLon !==false) { $oReverseGeocode = new ReverseGeocode($oDB); - $oReverseGeocode->setLanguagePreference($aLangPrefOrder); - - $oReverseGeocode->setLatLon($fLat, $fLon); $oReverseGeocode->setZoom(getParamInt('zoom', 18)); - $aLookup = $oReverseGeocode->lookup(); + $aLookup = $oReverseGeocode->lookup($fLat, $fLon); if (CONST_Debug) var_dump($aLookup); } else if ($sOutputFormat != 'html')