2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-website.php');
6 require_once(CONST_BasePath.'/lib/log.php');
7 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
8 require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
9 require_once(CONST_BasePath.'/lib/output.php');
10 ini_set('memory_limit', '200M');
12 $oParams = new Nominatim\ParameterParser();
15 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'xml');
18 $aLangPrefOrder = $oParams->getPreferredLanguages();
22 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
24 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
25 $oPlaceLookup->loadParamArray($oParams);
26 if ($sOutputFormat == 'geocodejson') {
27 $oPlaceLookup->setAddressDetails(true);
28 $oPlaceLookup->setAddressAdminLevels(true);
31 $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
32 $iOsmId = $oParams->getInt('osm_id', -1);
33 $fLat = $oParams->getFloat('lat');
34 $fLon = $oParams->getFloat('lon');
35 $iZoom = $oParams->getInt('zoom', 18);
37 if ($sOsmType && $iOsmId > 0) {
38 $aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
39 } elseif ($fLat !== false && $fLon !== false) {
40 $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
41 $oReverseGeocode->setZoom($iZoom);
43 $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
44 if (CONST_Debug) var_dump($oLookup);
47 $aPlaces = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
48 if (!empty($aPlaces)) {
49 $aPlace = reset($aPlaces);
52 } elseif ($sOutputFormat != 'html') {
53 userError('Need coordinates or OSM object to lookup.');
57 $fRadius = $fDiameter = getResultDiameter($aPlace);
58 $aOutlineResult = $oPlaceLookup->getOutlines(
67 if ($aOutlineResult) {
68 $aPlace = array_merge($aPlace, $aOutlineResult);
80 if ($sOutputFormat == 'html') {
81 $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
82 $sTileURL = CONST_Map_Tile_URL;
83 $sTileAttribution = CONST_Map_Tile_Attribution;
84 } elseif ($sOutputFormat == 'geocodejson') {
85 $sQuery = $fLat.','.$fLon;
86 if (isset($aPlace['place_id'])) {
87 $fDistance = chksql($oDB->getOne('SELECT ST_Distance(ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326), centroid) FROM placex where place_id='.$aPlace['place_id']));
91 $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat;
92 include(CONST_BasePath.'/lib/template/address-'.$sOutputTemplate.'.php');