{
// 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);
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
$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;
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";
$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";
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')