]> git.openstreetmap.org Git - nominatim.git/blob - website/reverse.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / website / reverse.php
1 <?php
2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
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');
8
9         $oDB =& getDB();
10         ini_set('memory_limit', '200M');
11
12         // Format for output
13         $sOutputFormat = 'xml';
14         if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
15         {
16                 $sOutputFormat = $_GET['format'];
17         }
18
19         // Preferred language
20         $aLangPrefOrder = getPreferredLanguages();
21
22         $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
23
24
25         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'))
26         {
27                 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
28         }
29         else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
30         {
31                 $oReverseGeocode = new ReverseGeocode($oDB);
32                 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
33
34                 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
35                 $oReverseGeocode->setZoom(@$_GET['zoom']);
36
37                 $aLookup = $oReverseGeocode->lookup();
38                 if (CONST_Debug) var_dump($aLookup);
39         }
40         else
41         {
42                 $aLookup = null;
43         }
44
45         if ($aLookup)
46         {
47                 $oPlaceLookup = new PlaceLookup($oDB);
48                 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
49                 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
50                 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
51                 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
52
53                 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
54         }
55         else
56         {
57                 $aPlace = null;
58         }
59
60         logEnd($oDB, $hLog, sizeof($aPlace)?1:0);
61
62         if (CONST_Debug)
63         {
64                 var_dump($aPlace);
65                 exit;
66         }
67
68         include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');