]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/address-jsonv2.php
51d3e1a3027863c51815fccd8dd465855f6cd2fd
[nominatim.git] / lib / template / address-jsonv2.php
1 <?php
2         header ("Content-Type: application/json; charset=UTF-8");
3         header("Access-Control-Allow-Origin: *");
4
5         $aFilteredPlaces = array();
6
7         if (!sizeof($aPlace))
8         {
9                 if ($sError)
10                         $aFilteredPlaces['error'] = $sError;
11                 else
12                         $aFilteredPlaces['error'] = 'Unable to geocode';
13         }
14         else
15         {
16                 if ($aPlace['place_id']) $aFilteredPlaces['place_id'] = $aPlace['place_id'];
17                 $aFilteredPlaces['licence'] = "Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.";
18                 $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':'')));
19                 if ($sOSMType)
20                 {
21                         $aFilteredPlaces['osm_type'] = $sOSMType;
22                         $aFilteredPlaces['osm_id'] = $aPlace['osm_id'];
23                 }
24                 if (isset($aPlace['lat'])) $aFilteredPlaces['lat'] = $aPlace['lat'];
25                 if (isset($aPlace['lon'])) $aFilteredPlaces['lon'] = $aPlace['lon'];
26                 $aFilteredPlaces['category'] = $aPlace['class'];
27                 $aFilteredPlaces['type'] = $aPlace['type'];
28                 $aFilteredPlaces['addresstype'] = strtolower($aPlace['addresstype']);
29
30                 $aFilteredPlaces['display_name'] = $aPlace['langaddress'];
31                 $aFilteredPlaces['name'] = $aPlace['placename'];
32                 if ($bShowAddressDetails && $aAddress && sizeof($aAddress)) $aFilteredPlaces['address'] = $aAddress;
33         }
34
35         if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_]+$/',$_GET['json_callback']))
36         {
37                 echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
38         }
39         else
40         {
41                 echo javascript_renderData($aFilteredPlaces);
42         }
43
44