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

Nominatim (OpenStreet) city/city_district parsing of Place object #252

Closed
VitaliyZaharenko opened this issue Apr 12, 2019 · 1 comment
Closed

Comments

@VitaliyZaharenko
Copy link

VitaliyZaharenko commented Apr 12, 2019

When parsing a response from openstreetmap geocoder nominatim in a function
private func parseResultPlace(_ json: JSON) -> Place
the library is trying to access a fields "address" -> "city", "address" -> "city_district" that do not exist.

Example request URL:
https://nominatim.openstreetmap.org/reverse?format=json&lat=55.766403&lon=37.584307&addressdetails=1&limit=1

Example response JSON:

{
    "place_id": 198709562,
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "osm_type": "relation",
    "osm_id": 3834185,
    "lat": "55.76649205",
    "lon": "37.5847426655174",
    "display_name": "Школа №1950, 28 с1, Зоологическая улица, Кудрино, Presnensky District, Central Administrative Okrug, Moscow, Central Federal District, 123056, Russia",
    "address": {
        "school": "Школа №1950",
        "house_number": "28 с1",
        "road": "Зоологическая улица",
        "suburb": "Presnensky District",
        "state_district": "Central Administrative Okrug",
        "state": "Moscow",
        "postcode": "123056",
        "country": "Russia",
        "country_code": "ru"
    },
    "boundingbox": [
        "55.7661513",
        "55.7668406",
        "37.5841336",
        "37.585355"
    ]
}

It seems we need to send an additional request with osm_id to get the city
Address lookup section in a link below:
https://wiki.openstreetmap.org/wiki/Nominatim

@malcommac
Copy link
Owner

I've tried to get lookup data from osm_id:

https://nominatim.openstreetmap.org/reverse?format=json&osm_type=R&osm_id=3834185&addressdetails=1&extratags=1

but I didn't get any extra data, in fact it's the same place in address:

{
    "place_id": 198709562,
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "osm_type": "relation",
    "osm_id": 3834185,
    "lat": "55.76649205",
    "lon": "37.5847426655174",
    "display_name": "Школа №1950, 28 с1, Зоологическая улица, Кудрино, Presnensky District, Central Administrative Okrug, Moscow, Central Federal District, 123056, Russia",
    "address": {
        "school": "Школа №1950",
        "house_number": "28 с1",
        "road": "Зоологическая улица",
        "suburb": "Presnensky District",
        "state_district": "Central Administrative Okrug",
        "state": "Moscow",
        "postcode": "123056",
        "country": "Russia",
        "country_code": "ru"
    },
    "extratags": {},
    "boundingbox": [
        "55.7661513",
        "55.7668406",
        "37.5841336",
        "37.585355"
    ]
}

I've also tried with Rome:

https://nominatim.openstreetmap.org/reverse?format=json&lat=41.931725&lon=12.517384&addressdetails=1&limit=1

And the result contains the city data:

{
    "place_id": 198986782,
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "osm_type": "relation",
    "osm_id": 5473366,
    "lat": "41.9279026",
    "lon": "12.5157982106648",
    "display_name": "Quartiere XVII Trieste, Via Acherusio, Municipio Roma II, Rome, RM, Lazio, 00199, Italy",
    "address": {
        "address29": "Quartiere XVII Trieste",
        "road": "Via Acherusio",
        "suburb": "Municipio Roma II",
        "city": "Rome",
        "county": "RM",
        "state": "Lazio",
        "postcode": "00199",
        "country": "Italy",
        "country_code": "it"
    },
    "boundingbox": [
        "41.9129308",
        "41.9428268",
        "12.4984614",
        "12.5266728"
    ]
}

I think it maybe a point with missing data.

@malcommac malcommac changed the title ParseError when using openstreetmap(nominatim) reverse geocoder Nominatim (OpenStreet) city/city_district parsing of Place object Sep 14, 2019
@malcommac malcommac self-assigned this Sep 14, 2019
abakhtin added a commit to abakhtin/SwiftLocation that referenced this issue Sep 20, 2019
* commit 'e1eb681a94ba338bc92c4b529369c4318797186f':
  Added swift-package tools to 5.x
  Fixed never executed statment
  Updated podspec
  Bump to 4.1.0
  malcommac#248 Added documentation for dataFrequency
  malcommac#248 Added dataFrequency filter inside the LocationRequest object
  malcommac#252 Parsing of the place_id for OpenStreetMap in Place object (place_id)
  malcommac#261 Moved sources to Sources/SwiftLocation subdirectory to be compatible with Swift Package Manager
  malcommac#262 Added rawData property to get the raw JSON parsed from Place when using Google/OS services. Parsed place_id of Google Maps in identifier property.
  malcommac#263 GeocoderRequest.Options init() is now public

# Conflicts:
#	SwiftLocation.xcodeproj/project.pbxproj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants