]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-jsonv2.php
Fix repeating lat twice in span instead of lat, lon.
[nominatim.git] / lib / template / search-jsonv2.php
1 <?php
2         header("Content-Type: application/json; charset=UTF-8");
3         header("Access-Control-Allow-Origin: *");
4
5         $aFilteredPlaces = array();
6         foreach($aSearchResults as $iResNum => $aPointDetails)
7         {
8                 $aPlace = array(
9                                 'place_id'=>$aPointDetails['place_id'],
10                                 'licence'=>"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.",
11                         );
12
13                 $sOSMType = ($aPointDetails['osm_type'] == 'N'?'node':($aPointDetails['osm_type'] == 'W'?'way':($aPointDetails['osm_type'] == 'R'?'relation':'')));
14                 if ($sOSMType)
15                 {
16                         $aPlace['osm_type'] = $sOSMType;
17                         $aPlace['osm_id'] = $aPointDetails['osm_id'];
18                 }
19
20                 if (isset($aPointDetails['aBoundingBox']))
21                 {
22                         $aPlace['boundingbox'] = array(
23                                 $aPointDetails['aBoundingBox'][0],
24                                 $aPointDetails['aBoundingBox'][1],
25                                 $aPointDetails['aBoundingBox'][2],
26                                 $aPointDetails['aBoundingBox'][3]);
27
28                         if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
29                         {
30                                 $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
31                         }
32                 }
33
34                 if (isset($aPointDetails['zoom']))
35                 {
36                         $aPlace['zoom'] = $aPointDetails['zoom'];
37                 }
38
39                 $aPlace['lat'] = $aPointDetails['lat'];
40                 $aPlace['lon'] = $aPointDetails['lon'];
41                 $aPlace['display_name'] = $aPointDetails['name'];
42
43                 $aPlace['category'] = $aPointDetails['class'];
44                 $aPlace['type'] = $aPointDetails['type'];
45                 if ($aPointDetails['icon'])
46                 {
47                         $aPlace['icon'] = $aPointDetails['icon'];
48                 }
49
50                 if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0)
51                 {
52                         $aPlace['address'] = $aPointDetails['address'];
53                 }
54
55                 $aFilteredPlaces[] = $aPlace;
56         }
57
58         if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_.]+$/',$_GET['json_callback']))
59         {
60                 echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
61         }
62         else
63         {
64                 echo javascript_renderData($aFilteredPlaces);
65         }