Search code examples
here-api

Reverse geocode: City same as country in response?


I'm using the HERE Maps reverse geocode API in, and a user from Pakistan sent a report that both the country and city are being reported as "Pakistan" for the co-ordinate pair 31.522473692893982, 74.33312326669693. I have double-checked and found the same error; this is the response:

{"items":[{"title":"Pakistan, Pakistan","id":"here:cm:namedplace:22928320","resultType":"locality","localityType":"city","address":{"label":"Pakistan, Pakistan","countryCode":"PAK","countryName":"Pakistan","city":"Pakistan"},"position":{"lat":33.70964,"lng":73.07545},"distance":0,"mapView":{"west":60.87305,"south":23.7033,"east":77.13585,"north":37.07742}}]}

Both countryName and city are reported as "Pakistan" – this is incorrect factually and confusing to the user. This is also hard to deal with programmatically in my app – city should be blank if it doesn't exist and I can code a check for that.

The above is a co-ordinate from Lahore, the 18th largest city in the world! I get this same error when using the co-ordinate pair 31.5204, 74.3587 – which Google reports as the center of Lahore. There is no excuse for HERE not to get this major city right at least, even at a locality level.

Thank you,

Naved


Solution

  • This can be indeed confusing. Try the Places API instead. For the coordinates you used, it returns Lahore.

    GET https://places.ls.hereapi.com/places/v1/discover/search?
      at=31.522473692893982,74.33312326669693&
      q=31.522473692893982,74.33312326669693&
      apikey={{apiKey}}
    

    Result

    {
        "results": {
            "items": [
                {
                    "position": [
                        31.522474,
                        74.333123
                    ],
                    "distance": 0,
                    "title": "Lahore",
                    "category": {
                        "id": "city-town-village",
                        "title": "City, Town or Village",
                        "href": "https://places.ls.hereapi.com/places/v1/categories/places/city-town-village?app_id=ZKnEmI4zhXnsDjVYNZLX&app_code=T-tTxarHYiInPeS4P52WdA",
                        "type": "urn:nlp-types:category",
                        "system": "places"
                    },
                    "icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/35.icon",
                    "vicinity": "Pakistan",
                    "having": [],
                    "type": "urn:nlp-types:place",
                    "href": "https://places.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPUxhaG9yZTtsYXQ9MzEuNTIyNDczNjkyODkzOTgyO2xvbj03NC4zMzMxMjMyNjY2OTY5MztjaXR5PUxhaG9yZTtjb3VudHJ5PVBBSztjb3VudHk9UGFraXN0YW47Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=Zmxvdy1pZD1hZWIzOGQxMS01NTUyLTUyNGEtOTNjYi01NDk1NjA1MzAzZWZfMTU5MTUyMjcxNDkwM18zNTU5Xzc4MTImcmFuaz0w?app_id=ZKnEmI4zhXnsDjVYNZLX&app_code=T-tTxarHYiInPeS4P52WdA",
                    "id": "loc-dmVyc2lvbj0xO3RpdGxlPUxhaG9yZTtsYXQ9MzEuNTIyNDczNjkyODkzOTgyO2xvbj03NC4zMzMxMjMyNjY2OTY5MztjaXR5PUxhaG9yZTtjb3VudHJ5PVBBSztjb3VudHk9UGFraXN0YW47Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw"
                }
            ]
        },
        "search": {
            "context": {
                "location": {
                    "position": [
                        31.522474,
                        74.333123
                    ],
                    "address": {
                        "text": "Lahore<br/>Pakistan",
                        "city": "Lahore",
                        "county": "Pakistan",
                        "country": "Pakistan",
                        "countryCode": "PAK"
                    }
                },
                "type": "urn:nlp-types:place",
                "href": "https://places.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPUxhaG9yZTtsYXQ9MzEuNTIyNDczNjkyODkzOTgyO2xvbj03NC4zMzMxMjMyNjY2OTY5MztjaXR5PUxhaG9yZTtjb3VudHJ5PVBBSztjb3VudHk9UGFraXN0YW47Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=ZKnEmI4zhXnsDjVYNZLX&app_code=T-tTxarHYiInPeS4P52WdA"
            }
        }
    }