2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
4 require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
5 require_once(CONST_BasePath.'/lib/log.php');
6 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
7 require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
9 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
11 $fLoadAvg = getLoadAverage();
12 if ($fLoadAvg > 2) sleep(60);
13 if ($fLoadAvg > 4) sleep(120);
16 echo "Bulk User: Temporary block due to high server load\n";
23 $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
24 $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
25 $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
26 $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
27 if ( ( ($bAsGeoJSON?1:0)
32 ) > CONST_PolygonOutput_MaximumTypes)
34 if (CONST_PolygonOutput_MaximumTypes)
36 userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
40 userError("Polygon output is disabled");
46 // Polygon simplification threshold (optional)
48 if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
52 ini_set('memory_limit', '200M');
55 $sOutputFormat = 'xml';
56 if (isset($_GET['format']) && ( $_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
58 $sOutputFormat = $_GET['format'];
62 $aLangPrefOrder = getPreferredLanguages();
64 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
67 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'))
69 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
71 else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
73 $oReverseGeocode = new ReverseGeocode($oDB);
74 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
76 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
77 $oReverseGeocode->setZoom(@$_GET['zoom']);
79 $aLookup = $oReverseGeocode->lookup();
80 if (CONST_Debug) var_dump($aLookup);
89 $oPlaceLookup = new PlaceLookup($oDB);
90 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
91 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
92 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
93 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
95 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
97 $oPlaceLookup->setIncludePolygonAsPoints($bAsPoints);
98 $oPlaceLookup->setIncludePolygonAsText($bAsText);
99 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
100 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
101 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
102 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
104 $fRadius = $fDiameter = getResultDiameter($aPlace);
105 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius);
109 $aPlace = array_merge($aPlace, $aOutlineResult);
124 if ($sOutputFormat=='html')
126 $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
127 $sTileURL = CONST_Map_Tile_URL;
128 $sTileAttribution = CONST_Map_Tile_Attribution;
130 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');