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');
10 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
12 $fLoadAvg = getLoadAverage();
13 if ($fLoadAvg > 2) sleep(60);
14 if ($fLoadAvg > 4) sleep(120);
17 echo "Bulk User: Temporary block due to high server load\n";
24 $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
25 $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
26 $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
27 $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
28 if ( ( ($bAsGeoJSON?1:0)
33 ) > CONST_PolygonOutput_MaximumTypes)
35 if (CONST_PolygonOutput_MaximumTypes)
37 userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
41 userError("Polygon output is disabled");
47 // Polygon simplification threshold (optional)
49 if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
53 ini_set('memory_limit', '200M');
56 $sOutputFormat = 'xml';
57 if (isset($_GET['format']) && ( $_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
59 $sOutputFormat = $_GET['format'];
63 $aLangPrefOrder = getPreferredLanguages();
65 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
68 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'))
70 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
72 else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
74 $oReverseGeocode = new ReverseGeocode($oDB);
75 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
77 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
78 $oReverseGeocode->setZoom(@$_GET['zoom']);
80 $aLookup = $oReverseGeocode->lookup();
81 if (CONST_Debug) var_dump($aLookup);
90 $oPlaceLookup = new PlaceLookup($oDB);
91 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
92 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
93 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
94 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
96 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
98 $oPlaceLookup->setIncludePolygonAsPoints($bAsPoints);
99 $oPlaceLookup->setIncludePolygonAsText($bAsText);
100 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
101 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
102 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
103 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
105 $fRadius = $fDiameter = getResultDiameter($aPlace);
106 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius);
110 $aPlace = array_merge($aPlace, $aOutlineResult);
125 if ($sOutputFormat=='html')
127 $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
128 $sTileURL = CONST_Map_Tile_URL;
129 $sTileAttribution = CONST_Map_Tile_Attribution;
131 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');