]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-geocodejson.php
FAQ: more answers regarding nominatim.so file permissions
[nominatim.git] / lib / template / search-geocodejson.php
1 <?php
2
3 $aFilteredPlaces = array();
4 foreach ($aSearchResults as $iResNum => $aPointDetails) {
5     $aPlace = array(
6                'type' => 'Feature',
7                'properties' => array(
8                                 'geocoding' => array()
9                                )
10               );
11
12     if (isset($aPlace['place_id'])) $aPlace['properties']['geocoding']['place_id'] = $aPointDetails['place_id'];
13     $sOSMType = formatOSMType($aPlace['osm_type']);
14     if ($sOSMType) {
15         $aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
16         $aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
17     }
18
19     $aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
20
21     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];
22
23     $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
24
25     $aFieldMappings = array(
26                        'house_number' => 'housenumber',
27                        'road' => 'street',
28                        'locality' => 'locality',
29                        'postcode' => 'postcode',
30                        'city' => 'city',
31                        'district' => 'district',
32                        'county' => 'county',
33                        'state' => 'state',
34                        'country' => 'country'
35                       );
36
37     foreach ($aFieldMappings as $sFrom => $sTo) {
38         if (isset($aPointDetails['address'][$sFrom])) {
39             $aPlace['properties']['geocoding'][$sTo] = $aPointDetails['address'][$sFrom];
40         }
41     }
42
43     $aPlace['properties']['geocoding']['admin'] = $aPointDetails['aAddressAdminLevels'];
44
45     if (isset($aPointDetails['asgeojson'])) {
46         $aPlace['geometry'] = json_decode($aPointDetails['asgeojson']);
47     } else {
48         $aPlace['geometry'] = array(
49                                'type' => 'Point',
50                                'coordinates' => array(
51                                                  (float) $aPointDetails['lon'],
52                                                  (float) $aPointDetails['lat']
53                                                 )
54                               );
55     }
56     $aFilteredPlaces[] = $aPlace;
57 }
58
59
60 javascript_renderData(array(
61                        'type' => 'FeatureCollection',
62                        'geocoding' => array(
63                                        'version' => '0.1.0',
64                                        'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
65                                        'licence' => 'ODbL',
66                                        'query' => $sQuery
67                                       ),
68                        'features' => $aFilteredPlaces
69                       ));