Kokers
Kokers

Reputation: 1828

HERE Geocoder Autocomplete API matchLevel parameter

Is there a way to get results restricted based on matchLevel? So if we are using geocoding to search for cities, we could use:

matchLevel : 'city'

to get results with only that?

Currently when sending request with query for example "London" we get all kinds of results with districts, counties, cities. I don't see a way to restrict those results to just city. Using resultType=areas is not enough. For a workaround currently we filter results after the response to show only those with matchLevel=city but we've increased maxresults to get enough to filter from. Is there maybe some beta/hidden parameter we could use?

Upvotes: 0

Views: 224

Answers (1)

Kokers
Kokers

Reputation: 1828

Because it's not possible to do it directly in API, the only solution is in fact filtering results. For anyone in need, this is what I use. You can adjust it to your needs.

request.onload = function () {
    if (request.status >= 200 && request.status < 400) {
        // Success!
        var data = JSON.parse(request.responseText);

        var list = [];
        var total = 0;
        for (var i = 0; i < data.suggestions.length; i++) {
            if (data.suggestions[i].matchLevel == "city" && list.indexOf(data.suggestions[i].address.city + ', ' + data.suggestions[i].address.country) < 0) {
                list.push(data.suggestions[i].address.city + ', ' + data.suggestions[i].address.country);
            }
        }

    }
};

Upvotes: 1

Related Questions