Merge pull request #305 from lonvia/api-extratags

Add new parameters to export name and extratags information
This commit is contained in:
Sarah Hoffmann
2015-08-11 22:19:36 +02:00
18 changed files with 343 additions and 67 deletions

View File

@@ -6,6 +6,8 @@
protected $aLangPrefOrder = array();
protected $bIncludeAddressDetails = false;
protected $bIncludeExtraTags = false;
protected $bIncludeNameDetails = false;
protected $bIncludePolygonAsPoints = false;
protected $bIncludePolygonAsText = false;
@@ -68,6 +70,16 @@
return $this->bIncludeAddressDetails;
}
function getIncludeExtraTags()
{
return $this->bIncludeExtraTags;
}
function getIncludeNameDetails()
{
return $this->bIncludeNameDetails;
}
function setIncludePolygonAsPoints($b = true)
{
$this->bIncludePolygonAsPoints = $b;
@@ -214,6 +226,11 @@
function loadParamArray($aParams)
{
if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
if ((float) CONST_Postgresql_Version > 9.2)
{
if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
}
if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
@@ -389,6 +406,8 @@
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
if ($this->bIncludeExtraTags) $sSQL .= "hstore_to_json(extratags)::text as extra,";
if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
@@ -405,6 +424,8 @@
$sSQL .= ",langaddress ";
$sSQL .= ",placename ";
$sSQL .= ",ref ";
if ($this->bIncludeExtraTags) $sSQL .= ",extratags";
if ($this->bIncludeNameDetails) $sSQL .= ",name";
$sSQL .= ",extratags->'place' ";
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank)
@@ -414,6 +435,8 @@
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."-1.15 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_tiger.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
@@ -427,6 +450,8 @@
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."-1.10 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_aux.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
@@ -1756,6 +1781,30 @@
}
}
if ($this->bIncludeExtraTags)
{
if ($aResult['extra'])
{
$aResult['sExtraTags'] = json_decode($aResult['extra']);
}
else
{
$aResult['sExtraTags'] = array();
}
}
if ($this->bIncludeNameDetails)
{
if ($aResult['names'])
{
$aResult['sNameDetails'] = json_decode($aResult['names']);
}
else
{
$aResult['sNameDetails'] = array();
}
}
// Adjust importance for the number of exact string matches in the result
$aResult['importance'] = max(0.001,$aResult['importance']);
$iCountWords = 0;
@@ -1790,6 +1839,7 @@
{
$aResult['foundorder'] += 0.01;
}
if (CONST_Debug) { var_dump($aResult); }
$aSearchResults[$iResNum] = $aResult;
}
uasort($aSearchResults, 'byImportance');

View File

@@ -5,12 +5,16 @@
protected $iPlaceID;
protected $bIsTiger = false;
protected $sType = false;
protected $aLangPrefOrder = array();
protected $bAddressDetails = false;
protected $bExtraTags = false;
protected $bNameDetails = false;
function PlaceLookup(&$oDB)
{
$this->oDB =& $oDB;
@@ -26,6 +30,22 @@
$this->bAddressDetails = $bAddressDetails;
}
function setIncludeExtraTags($bExtraTags = false)
{
if ((float) CONST_Postgresql_Version > 9.2)
{
$this->bExtraTags = $bExtraTags;
}
}
function setIncludeNameDetails($bNameDetails = false)
{
if ((float) CONST_Postgresql_Version > 9.2)
{
$this->bNameDetails = $bNameDetails;
}
}
function setPlaceID($iPlaceID)
{
$this->iPlaceID = $iPlaceID;
@@ -37,9 +57,16 @@
$this->iPlaceID = $this->oDB->getOne($sSQL);
}
function setIsTiger($b = false)
function lookupPlace($details)
{
$this->bIsTiger = $b;
if (isset($details['place_id'])) $this->iPlaceID = $details['place_id'];
if (isset($details['type'])) $this->sType = $details['type'];
if (isset($details['osm_type']) && isset($details['osm_id']))
{
$this->setOSMID($details['osm_type'], $details['osm_id']);
}
return $this->lookup();
}
function lookup()
@@ -48,28 +75,33 @@
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted", $this->aLangPrefOrder))."]";
$sSQL = "select placex.place_id, partition, osm_type, osm_id, class, type, admin_level, housenumber, street, isin, postcode, country_code, extratags, parent_place_id, linked_place_id, rank_address, rank_search, ";
$sSQL .= " coalesce(importance,0.75-(rank_search::float/40)) as importance, indexed_status, indexed_date, wikipedia, calculated_country_code, ";
$sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= " (case when centroid is null then st_y(st_centroid(geometry)) else st_y(centroid) end) as lat,";
$sSQL .= " (case when centroid is null then st_x(st_centroid(geometry)) else st_x(centroid) end) as lon";
$sSQL .= " from placex where place_id = ".(int)$this->iPlaceID;
if ($this->bIsTiger)
if ($this->sType == 'tiger')
{
$sSQL = "select place_id,partition, 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level, housenumber, null as street, null as isin, postcode,";
$sSQL .= " 'us' as country_code, null as extratags, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,";
$sSQL .= " 'us' as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,";
$sSQL .= " coalesce(null,0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, 'us' as calculated_country_code, ";
$sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= " null as placename,";
$sSQL .= " null as ref,";
if ($this->bExtraTags) $sSQL .= " null as extra,";
if ($this->bNameDetails) $sSQL .= " null as names,";
$sSQL .= " st_y(centroid) as lat,";
$sSQL .= " st_x(centroid) as lon";
$sSQL .= " from location_property_tiger where place_id = ".(int)$this->iPlaceID;
}
else
{
$sSQL = "select placex.place_id, partition, osm_type, osm_id, class, type, admin_level, housenumber, street, isin, postcode, country_code, parent_place_id, linked_place_id, rank_address, rank_search, ";
$sSQL .= " coalesce(importance,0.75-(rank_search::float/40)) as importance, indexed_status, indexed_date, wikipedia, calculated_country_code, ";
$sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
if ($this->bExtraTags) $sSQL .= " hstore_to_json(extratags) as extra,";
if ($this->bNameDetails) $sSQL .= " hstore_to_json(name) as names,";
$sSQL .= " (case when centroid is null then st_y(st_centroid(geometry)) else st_y(centroid) end) as lat,";
$sSQL .= " (case when centroid is null then st_x(st_centroid(geometry)) else st_x(centroid) end) as lon";
$sSQL .= " from placex where place_id = ".(int)$this->iPlaceID;
}
$aPlace = $this->oDB->getRow($sSQL);
@@ -87,6 +119,29 @@
$aPlace['aAddress'] = $aAddress;
}
if ($this->bExtraTags)
{
if ($aPlace['extra'])
{
$aPlace['sExtraTags'] = json_decode($aPlace['extra']);
}
else
{
$aPlace['sExtraTags'] = array();
}
}
if ($this->bNameDetails)
{
if ($aPlace['names'])
{
$aPlace['sNameDetails'] = json_decode($aPlace['names']);
}
else
{
$aPlace['sNameDetails'] = array();
}
}
$aClassType = getClassTypes();
$sAddressType = '';
@@ -129,7 +184,7 @@
function getAddressNames()
{
$aAddressLines = $this->getAddressDetails(false);;
$aAddressLines = $this->getAddressDetails(false);
$aAddress = array();
$aFallback = array();

View File

@@ -9,8 +9,6 @@
protected $aLangPrefOrder = array();
protected $bShowAddressDetails = true;
function ReverseGeocode(&$oDB)
{
$this->oDB =& $oDB;
@@ -21,11 +19,6 @@
$this->aLangPrefOrder = $aLangPref;
}
function setIncludeAddressDetails($bAddressDetails = true)
{
$this->bAddressDetails = $bAddressDetails;
}
function setLatLon($fLat, $fLon)
{
$this->fLat = (float)$fLat;
@@ -171,13 +164,8 @@
}
}
$oPlaceLookup = new PlaceLookup($this->oDB);
$oPlaceLookup->setLanguagePreference($this->aLangPrefOrder);
$oPlaceLookup->setIncludeAddressDetails($this->bAddressDetails);
$oPlaceLookup->setPlaceId($iPlaceID);
$oPlaceLookup->setIsTiger($bPlaceIsTiger);
return $oPlaceLookup->lookup();
return array('place_id' => $iPlaceID,
'type' => $bPlaceIsTiger ? 'tiger' : 'osm');
}
}
?>

View File

@@ -39,6 +39,12 @@
exit;
}
function getParamBool($name, $default=false)
{
if (!isset($_GET[$name])) return $default;
return (bool) $_GET[$name];
}
function fail($sError, $sUserError = false)
{
@@ -668,12 +674,11 @@
}
function javascript_renderData($xVal)
function javascript_renderData($xVal, $iOptions = 0)
{
header("Access-Control-Allow-Origin: *");
$iOptions = 0;
if (defined('PHP_VERSION_ID') && PHP_VERSION_ID > 50400)
$iOptions = JSON_UNESCAPED_UNICODE;
$iOptions |= JSON_UNESCAPED_UNICODE;
$jsonout = json_encode($xVal, $iOptions);
if( ! isset($_GET['json_callback']))

View File

@@ -10,7 +10,7 @@
}
else
{
if ($aPlace['place_id']) $aFilteredPlaces['place_id'] = $aPlace['place_id'];
if (isset($aPlace['place_id'])) $aFilteredPlaces['place_id'] = $aPlace['place_id'];
$aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright";
$sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':'')));
if ($sOSMType)
@@ -21,8 +21,10 @@
if (isset($aPlace['lat'])) $aFilteredPlaces['lat'] = $aPlace['lat'];
if (isset($aPlace['lon'])) $aFilteredPlaces['lon'] = $aPlace['lon'];
$aFilteredPlaces['display_name'] = $aPlace['langaddress'];
if ($bShowAddressDetails) $aFilteredPlaces['address'] = $aPlace['aAddress'];
if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress'];
if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
}
javascript_renderData($aFilteredPlaces);
javascript_renderData($aFilteredPlaces, JSON_FORCE_OBJECT);

View File

@@ -23,16 +23,19 @@
$aFilteredPlaces['place_rank'] = $aPlace['rank_search'];
$aFilteredPlaces['category'] = $aPlace['class'];
$aFilteredPlaces['type'] = $aPlace['type'];
$aFilteredPlaces['category'] = $aPlace['class'];
$aFilteredPlaces['type'] = $aPlace['type'];
$aFilteredPlaces['importance'] = $aPlace['importance'];
$aFilteredPlaces['addresstype'] = strtolower($aPlace['addresstype']);
$aFilteredPlaces['addresstype'] = strtolower($aPlace['addresstype']);
$aFilteredPlaces['display_name'] = $aPlace['langaddress'];
$aFilteredPlaces['name'] = $aPlace['placename'];
if ($bShowAddressDetails && $aPlace['aAddress'] && sizeof($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress'];
$aFilteredPlaces['name'] = $aPlace['placename'];
if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress'];
if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
}
javascript_renderData($aFilteredPlaces);
javascript_renderData($aFilteredPlaces, JSON_FORCE_OBJECT);

View File

@@ -29,7 +29,8 @@
if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";
if ($bShowAddressDetails) {
if (isset($aPlace['aAddress']))
{
echo "<addressparts>";
foreach($aPlace['aAddress'] as $sKey => $sValue)
{
@@ -40,6 +41,28 @@
}
echo "</addressparts>";
}
if (isset($aPlace['sExtraTags']))
{
echo "<extratags>";
foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
{
echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
}
echo "</extratags>";
}
if (isset($aPlace['sNameDetails']))
{
echo "<namedetails>";
foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
{
echo '<name desc="'.htmlspecialchars($sKey).'">';
echo htmlspecialchars($sValue);
echo "</name>";
}
echo "</namedetails>";
}
}
echo "</reversegeocode>";

View File

@@ -74,6 +74,9 @@
$aPlace['geokml'] = $aPointDetails['askml'];
}
if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
$aFilteredPlaces[] = $aPlace;
}

View File

@@ -73,6 +73,9 @@
$aPlace['geokml'] = $aPointDetails['askml'];
}
if (isset($aPointDetails['sExtraTags'])) $aPlace['extratags'] = $aPointDetails['sExtraTags'];
if (isset($aPointDetails['sNameDetails'])) $aPlace['namedetails'] = $aPointDetails['sNameDetails'];
$aFilteredPlaces[] = $aPlace;
}

View File

@@ -88,20 +88,59 @@
echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
}
if (isset($aResult['address']) || isset($aResult['askml']))
{
echo ">";
}
$bHasDelim = false;
if (isset($aResult['askml']))
{
if (!$bHasDelim)
{
$bHasDelim = true;
echo ">";
}
echo "\n<geokml>";
echo $aResult['askml'];
echo "</geokml>";
}
if (isset($aResult['sExtraTags']))
{
if (!$bHasDelim)
{
$bHasDelim = true;
echo ">";
}
echo "\n<extratags>";
foreach ($aResult['sExtraTags'] as $sKey => $sValue)
{
echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
}
echo "</extratags>";
}
if (isset($aResult['sNameDetails']))
{
if (!$bHasDelim)
{
$bHasDelim = true;
echo ">";
}
echo "\n<namedetails>";
foreach ($aResult['sNameDetails'] as $sKey => $sValue)
{
echo '<name desc="'.htmlspecialchars($sKey).'">';
echo htmlspecialchars($sValue);
echo "</name>";
}
echo "</namedetails>";
}
if (isset($aResult['address']))
{
if (!$bHasDelim)
{
$bHasDelim = true;
echo ">";
}
echo "\n";
foreach($aResult['address'] as $sKey => $sValue)
{
@@ -112,7 +151,7 @@
}
}
if (isset($aResult['address']) || isset($aResult['askml']))
if ($bHasDelim)
{
echo "</place>";
}

View File

@@ -36,3 +36,28 @@ Feature: Reverse geocoding
| 0 | Kings Estate Drive | 84128 | us
And result 0 has attributes osm_id,osm_type
Scenario Outline: Reverse Geocoding with extratags
Given the request parameters
| extratags
| 1
When looking up <format> coordinates 48.86093,2.2978
Then result 0 has attributes extratags
Examples:
| format
| xml
| json
| jsonv2
Scenario Outline: Reverse Geocoding with namedetails
Given the request parameters
| namedetails
| 1
When looking up <format> coordinates 48.86093,2.2978
Then result 0 has attributes namedetails
Examples:
| format
| xml
| json
| jsonv2

View File

@@ -70,7 +70,7 @@ Feature: Search queries
Then result addresses contain
| ID | city
| 0 | Chicago
Scenario: No POI search with unbounded viewbox
Given the request parameters
| viewbox
@@ -202,3 +202,31 @@ Feature: Search queries
| 0.5
| 999
| nan
Scenario Outline: Search with extratags
Given the request parameters
| extratags
| 1
When sending <format> search query "Hauptstr"
Then result 0 has attributes extratags
And result 1 has attributes extratags
Examples:
| format
| xml
| json
| jsonv2
Scenario Outline: Search with namedetails
Given the request parameters
| namedetails
| 1
When sending <format> search query "Hauptstr"
Then result 0 has attributes namedetails
And result 1 has attributes namedetails
Examples:
| format
| xml
| json
| jsonv2

View File

@@ -51,6 +51,10 @@ Feature: Simple Tests
| limit | 1000
| dedupe | 1
| dedupe | 0
| extratags | 1
| extratags | 0
| namedetails | 1
| namedetails | 0
Scenario: Search with invalid output format
Given the request parameters

View File

@@ -34,10 +34,28 @@ def _parse_xml():
newresult = OrderedDict(node.attributes.items())
assert_not_in('address', newresult)
assert_not_in('geokml', newresult)
assert_not_in('extratags', newresult)
assert_not_in('namedetails', newresult)
address = OrderedDict()
for sub in node.childNodes:
if sub.nodeName == 'geokml':
newresult['geokml'] = sub.childNodes[0].toxml()
elif sub.nodeName == 'extratags':
newresult['extratags'] = {}
for tag in sub.childNodes:
assert_equals(tag.nodeName, 'tag')
attrs = dict(tag.attributes.items())
assert_in('key', attrs)
assert_in('value', attrs)
newresult['extratags'][attrs['key']] = attrs['value']
elif sub.nodeName == 'namedetails':
newresult['namedetails'] = {}
for tag in sub.childNodes:
assert_equals(tag.nodeName, 'name')
attrs = dict(tag.attributes.items())
assert_in('desc', attrs)
newresult['namedetails'][attrs['desc']] = tag.firstChild.nodeValue.strip()
elif sub.nodeName == '#text':
pass
else:
@@ -65,6 +83,21 @@ def _parse_xml():
for sub in node.childNodes:
address[sub.nodeName] = sub.firstChild.nodeValue.strip()
world.results[0]['address'] = address
elif node.nodeName == 'extratags':
world.results[0]['extratags'] = {}
for tag in node.childNodes:
assert_equals(tag.nodeName, 'tag')
attrs = dict(tag.attributes.items())
assert_in('key', attrs)
assert_in('value', attrs)
world.results[0]['extratags'][attrs['key']] = attrs['value']
elif node.nodeName == 'namedetails':
world.results[0]['namedetails'] = {}
for tag in node.childNodes:
assert_equals(tag.nodeName, 'name')
attrs = dict(tag.attributes.items())
assert_in('desc', attrs)
world.results[0]['namedetails'][attrs['desc']] = tag.firstChild.nodeValue.strip()
elif node.nodeName == "#text":
pass
else:
@@ -92,6 +125,8 @@ def api_result_is_valid(step, fmt):
_parse_xml()
elif world.response_format == 'json':
world.results = json.JSONDecoder(object_pairs_hook=OrderedDict).decode(world.page)
if world.request_type == 'reverse':
world.results = (world.results,)
else:
assert False, "Unknown page format: %s" % (world.response_format)

View File

@@ -10,6 +10,7 @@ import logging
logger = logging.getLogger(__name__)
def api_call(requesttype):
world.request_type = requesttype
world.json_callback = None
data = urllib.urlencode(world.params)
url = "%s/%s?%s" % (world.config.base_url, requesttype, data)

View File

@@ -27,10 +27,6 @@
$sOutputFormat = $_GET['format'];
}
// Show address breakdown
$bShowAddressDetails = true;
if (isset($_GET['addressdetails'])) $bShowAddressDetails = (bool)$_GET['addressdetails'];
// Preferred language
$aLangPrefOrder = getPreferredLanguages();
@@ -42,7 +38,9 @@
{
$oPlaceLookup = new PlaceLookup($oDB);
$oPlaceLookup->setLanguagePreference($aLangPrefOrder);
$oPlaceLookup->setIncludeAddressDetails($bShowAddressDetails);
$oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
$oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
$oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
$aOsmIds = explode(',', $_GET['osm_ids']);

View File

@@ -28,40 +28,52 @@
$sOutputFormat = $_GET['format'];
}
// Show address breakdown
$bShowAddressDetails = true;
if (isset($_GET['addressdetails'])) $bShowAddressDetails = (bool)$_GET['addressdetails'];
// Preferred language
$aLangPrefOrder = getPreferredLanguages();
$hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
if (isset($_GET['osm_type']) && isset($_GET['osm_id']) && (int)$_GET['osm_id'] && ($_GET['osm_type'] == 'N' || $_GET['osm_type'] == 'W' || $_GET['osm_type'] == 'R'))
{
$oPlaceLookup = new PlaceLookup($oDB);
$oPlaceLookup->setLanguagePreference($aLangPrefOrder);
$oPlaceLookup->setIncludeAddressDetails($bShowAddressDetails);
$oPlaceLookup->setOSMID($_GET['osm_type'], $_GET['osm_id']);
$aPlace = $oPlaceLookup->lookup();
$aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
}
else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
{
$oReverseGeocode = new ReverseGeocode($oDB);
$oReverseGeocode->setLanguagePreference($aLangPrefOrder);
$oReverseGeocode->setIncludeAddressDetails($bShowAddressDetails);
$oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
$oReverseGeocode->setZoom(@$_GET['zoom']);
$aPlace = $oReverseGeocode->lookup();
$aLookup = $oReverseGeocode->lookup();
if (CONST_Debug) var_dump($aLookup);
}
else
{
$aLookup = null;
}
if ($aLookup)
{
$oPlaceLookup = new PlaceLookup($oDB);
$oPlaceLookup->setLanguagePreference($aLangPrefOrder);
$oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
$oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
$oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
$aPlace = $oPlaceLookup->lookupPlace($aLookup);
}
else
{
$aPlace = null;
}
if (CONST_Debug) exit;
if (CONST_Debug)
{
var_dump($aPlace);
exit;
}
include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');

View File

@@ -126,6 +126,8 @@
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
if ($oGeocode->getIncludeAddressDetails()) $sMoreURL .= '&addressdetails=1';
if ($oGeocode->getIncludeExtraTags()) $sMoreURL .= '&extratags=1';
if ($oGeocode->getIncludeNameDetails()) $sMoreURL .= '&namedetails=1';
if ($sViewBox) $sMoreURL .= '&viewbox='.urlencode($sViewBox);
if (isset($_GET['nearlat']) && isset($_GET['nearlon'])) $sMoreURL .= '&nearlat='.(float)$_GET['nearlat'].'&nearlon='.(float)$_GET['nearlon'];
$sMoreURL .= '&q='.urlencode($sQuery);