3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 // https://github.com/geocoders/geocodejson-spec/
13 $aFilteredPlaces = array();
17 $aFilteredPlaces['error'] = $sError;
19 $aFilteredPlaces['error'] = 'Unable to geocode';
21 javascript_renderData($aFilteredPlaces);
23 $aFilteredPlaces = array(
25 'properties' => array(
26 'geocoding' => array()
30 if (isset($aPlace['place_id'])) {
31 $aFilteredPlaces['properties']['geocoding']['place_id'] = $aPlace['place_id'];
33 $sOSMType = formatOSMType($aPlace['osm_type']);
35 $aFilteredPlaces['properties']['geocoding']['osm_type'] = $sOSMType;
36 $aFilteredPlaces['properties']['geocoding']['osm_id'] = $aPlace['osm_id'];
39 $aFilteredPlaces['properties']['geocoding']['osm_key'] = $aPlace['class'];
40 $aFilteredPlaces['properties']['geocoding']['osm_value'] = $aPlace['type'];
42 $aFilteredPlaces['properties']['geocoding']['type'] = addressRankToGeocodeJsonType($aPlace['rank_address']);
44 $aFilteredPlaces['properties']['geocoding']['accuracy'] = (int) $fDistance;
46 $aFilteredPlaces['properties']['geocoding']['label'] = $aPlace['langaddress'];
48 if ($aPlace['placename'] !== null) {
49 $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
52 if (isset($aPlace['address'])) {
53 $aPlace['address']->addGeocodeJsonAddressParts(
54 $aFilteredPlaces['properties']['geocoding']
57 $aFilteredPlaces['properties']['geocoding']['admin']
58 = $aPlace['address']->getAdminLevels();
61 if (isset($aPlace['asgeojson'])) {
62 $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson'], true);
64 $aFilteredPlaces['geometry'] = array(
66 'coordinates' => array(
67 (float) $aPlace['lon'],
68 (float) $aPlace['lat']
73 javascript_renderData(array(
74 'type' => 'FeatureCollection',
77 'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
81 'features' => array($aFilteredPlaces)