Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'type' field in the geocodejson response #2681

Merged
merged 4 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/admin/Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ breaking changes. **Please read them before running the migration.**
If you are migrating from a version <3.6, then you still have to follow
the manual migration steps up to 3.6.

## 4.0.0 -> master

### geocodejson output changed

The `type` field of the geocodejson output has changed. It now contains
the address class of the object instead of the value of the OSM tag. If
your client has used the `type` field, switch them to read `osm_value`
instead.

## 3.7.0 -> 4.0.0

### NOMINATIM_PHRASE_CONFIG removed
Expand Down
5 changes: 4 additions & 1 deletion docs/api/Output.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ The GeocodeJSON format follows the
The following feature attributes are implemented:

* `osm_type`, `osm_id` - reference to the OSM object (unofficial extension, [see notes](#osm-reference))
* `type` - value of the main tag of the object (e.g. residential, restaurant, ...)
* `type` - the 'address level' of the object ('house', 'street', `district`, `city`,
`county`, `state`, `country`, `locality`)
* `osm_key`- key of the main tag of the OSM object (e.g. boundary, highway, amenity)
* `osm_value` - value of the main tag of the OSM object (e.g. residential, restaurant)
* `label` - full comma-separated address
* `name` - localised name of the place
* `housenumber`, `street`, `locality`, `district`, `postcode`, `city`,
Expand Down
30 changes: 30 additions & 0 deletions lib-php/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ function parseLatLon($sQuery)
return array($sFound, $fQueryLat, $fQueryLon);
}

function addressRankToGeocodeJsonType($iAddressRank)
{
if ($iAddressRank >= 29 && $iAddressRank <= 30) {
return 'house';
}
if ($iAddressRank >= 26 && $iAddressRank < 28) {
return 'street';
}
if ($iAddressRank >= 22 && $iAddressRank < 26) {
return 'locality';
}
if ($iAddressRank >= 17 && $iAddressRank < 22) {
return 'district';
}
if ($iAddressRank >= 13 && $iAddressRank < 17) {
return 'city';
}
if ($iAddressRank >= 10 && $iAddressRank < 13) {
return 'county';
}
if ($iAddressRank >= 5 && $iAddressRank < 10) {
return 'state';
}
if ($iAddressRank >= 4 && $iAddressRank < 5) {
return 'country';
}

return 'locality';
}

if (!function_exists('array_key_last')) {
function array_key_last(array $array)
{
Expand Down
4 changes: 3 additions & 1 deletion lib-php/template/search-geocodejson.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
$aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
$aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
}
$aPlace['properties']['geocoding']['osm_key'] = $aPointDetails['class'];
$aPlace['properties']['geocoding']['osm_value'] = $aPointDetails['type'];

$aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
$aPlace['properties']['geocoding']['type'] = addressRankToGeocodeJsonType($aPointDetails['rank_address']);

$aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];

Expand Down