Here API - geocode search using zipcode not returning city field

Viewed 157

I am searching a City and state by zip code using below HERE API

https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=43026&apiKey=key&in=countryCode%3AUSA, but it's not returning city field. the result is below

{ "items": [ { "title": "43026, OH, United States", "id": "here:cm:namedplace:22236211", "resultType": "locality", "localityType": "postalCode", "address": { "label": "43026, OH, United States", "countryCode": "USA", "countryName": "United States", "stateCode": "OH", "state": "Ohio", "postalCode": "43026" }, "position": { "lat": 39.9972, "lng": -83.15518 }, "mapView": { "west": -83.0952, "south": 39.97889, "east": -83.26074, "north": 40.06921 }, "scoring": { "queryScore": 1, "fieldScore": { "postalCode": 1 } } } ] }

can anyone please help

1 Answers

If you run several queries against this api, you'll notice that some results contain a city, and some do not.

For example:

If we run (with api key set to a valid value): https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=60606&apiKey=key&in=countryCode%3AUSA

We get an address like so

"address": {
            "label": "60606, Chicago, IL, United States",
            "countryCode": "USA",
            "countryName": "United States",
            "stateCode": "IL",
            "state": "Illinois",
            "county": "Cook",
            "city": "Chicago",
            "postalCode": "60606"
        }

Which includes a city value.

Your query returns

"address": {
    "label": "43026, OH, United States",
    "countryCode": "USA",
    "countryName": "United States",
    "stateCode": "OH",
    "state": "Ohio",
    "postalCode": "43026"
},

Which is missing the city field.

You could try using the ZIP+4 code (if you have it) as mentioned in the API docs: https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics-api/code-geocode-hpc-hsn.html

For example, https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=43026-0001&apiKey=key&in=countryCode%3AUSA

"address": {
    "label": "43026-0001, Hilliard, OH, United States",
    "countryCode": "USA",
    "countryName": "United States",
    "stateCode": "OH",
    "state": "Ohio",
    "county": "Franklin",
    "city": "Hilliard",
    "postalCode": "43026-0001"
},

Will return us a city.

NB: Not all Zip+4 codes will return a city name. For example: 43026-0101 will not (this may be because it doesn't exist)

It doesn't look to me like there is any way to guarantee a city field response with just a ZIP code.

Related