]> git.openstreetmap.org Git - nominatim.git/blob - website/reverse.php
269229d36a71ea689723ee979a1d3a83ad0f705f
[nominatim.git] / website / reverse.php
1 <?php
2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
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');
11
12 $oParams = new Nominatim\ParameterParser();
13
14 // Format for output
15 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'xml');
16
17 // Preferred language
18 $aLangPrefOrder = $oParams->getPreferredLanguages();
19
20 $oDB =& getDB();
21
22 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
23
24 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
25 $oPlaceLookup->loadParamArray($oParams);
26 $oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
27
28 $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
29 $iOsmId = $oParams->getInt('osm_id', -1);
30 $fLat = $oParams->getFloat('lat');
31 $fLon = $oParams->getFloat('lon');
32 $iZoom = $oParams->getInt('zoom', 18);
33
34 if ($sOsmType && $iOsmId > 0) {
35     $aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
36 } elseif ($fLat !== false && $fLon !== false) {
37     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
38     $oReverseGeocode->setZoom($iZoom);
39
40     $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
41     if (CONST_Debug) var_dump($oLookup);
42
43     if ($oLookup) {
44         $aPlaces = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
45         if (sizeof($aPlaces)) {
46             $aPlace = reset($aPlaces);
47         }
48     }
49 } elseif ($sOutputFormat != 'html') {
50     userError("Need coordinates or OSM object to lookup.");
51 }
52
53 if (isset($aPlace)) {
54     $fRadius = $fDiameter = getResultDiameter($aPlace);
55     $aOutlineResult = $oPlaceLookup->getOutlines(
56         $aPlace['place_id'],
57         $aPlace['lon'],
58         $aPlace['lat'],
59         $fRadius
60     );
61
62     if ($aOutlineResult) {
63         $aPlace = array_merge($aPlace, $aOutlineResult);
64     }
65 } else {
66     $aPlace = [];
67 }
68
69
70 if (CONST_Debug) {
71     var_dump($aPlace);
72     exit;
73 }
74
75 if ($sOutputFormat == 'html') {
76     $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
77     $sTileURL = CONST_Map_Tile_URL;
78     $sTileAttribution = CONST_Map_Tile_Attribution;
79 }
80 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');