]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/address-xml.php
Merge pull request #219 from mizabrik/master
[nominatim.git] / lib / template / address-xml.php
1 <?php
2         header("content-type: text/xml; charset=UTF-8");
3
4         echo "<";
5         echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
6         echo ">\n";
7
8         echo "<reversegeocode";
9         echo " timestamp='".date(DATE_RFC822)."'";
10         echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
11         echo " querystring='".htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES)."'";
12         echo ">\n";
13
14         if (!sizeof($aPlace))
15         {
16                 if (isset($sError))
17                         echo "<error>$sError</error>";
18                 else
19                         echo "<error>Unable to geocode</error>";
20         }
21         else
22         {
23                 echo "<result";
24                 if ($aPlace['place_id']) echo ' place_id="'.$aPlace['place_id'].'"';
25                 $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':
26                 ($aPlace['osm_type'] == 'T'?'tiger':($aPlace['osm_type'] == 'I'?'interpolation':'')))));
27                 if ($sOSMType) echo ' osm_type="'.$sOSMType.'"'.' osm_id="'.$aPlace['osm_id'].'"';
28                 if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"';
29                 if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"';
30                 if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
31                 if (isset($aPlace['aBoundingBox']))
32                 {
33                         echo ' boundingbox="';
34                         echo join(',', $aPlace['aBoundingBox']);
35                         echo '"';
36
37                         if ($bAsPoints && isset($aPlace['aPolyPoints']))
38                         {
39                                 echo ' polygonpoints=\'';
40                                 echo json_encode($aPlace['aPolyPoints']);
41                                 echo '\'';
42                         }
43                 }
44
45                 if (isset($aPlace['asgeojson']))
46                 {
47                         echo ' geojson=\'';
48                         echo $aPlace['asgeojson'];
49                         echo '\'';
50                 }
51
52                 if (isset($aPlace['assvg']))
53                 {
54                         echo ' geosvg=\'';
55                         echo $aPlace['assvg'];
56                         echo '\'';
57                 }
58
59                 if (isset($aPlace['astext']))
60                 {
61                         echo ' geotext=\'';
62                         echo $aPlace['astext'];
63                         echo '\'';
64                 }
65                 echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";
66
67                 if (isset($aPlace['aAddress']))
68                 {
69                         echo "<addressparts>";
70                         foreach($aPlace['aAddress'] as $sKey => $sValue)
71                         {
72                                 $sKey = str_replace(' ','_',$sKey);
73                                 echo "<$sKey>";
74                                 echo htmlspecialchars($sValue);
75                                 echo "</$sKey>";
76                         }
77                         echo "</addressparts>";
78                 }
79
80                 if (isset($aPlace['sExtraTags']))
81                 {
82                         echo "<extratags>";
83                         foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
84                         {
85                                 echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
86                         }
87                         echo "</extratags>";
88                 }
89
90                 if (isset($aPlace['sNameDetails']))
91                 {
92                         echo "<namedetails>";
93                         foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
94                         {
95                                 echo '<name desc="'.htmlspecialchars($sKey).'">';
96                                 echo htmlspecialchars($sValue);
97                                 echo "</name>";
98                         }
99                         echo "</namedetails>";
100                 }
101
102                 if (isset($aPlace['askml']))
103                 {
104                         echo "\n<geokml>";
105                         echo $aPlace['askml'];
106                         echo "</geokml>";
107                 }
108
109         }
110
111         echo "</reversegeocode>";