mshwf
mshwf

Reputation: 7449

How can I retrieve result from my country in here maps?

I use this function to retrieve results of the user search of a destination, but this gets all results from the world, how can I distinct results from certain country

 function getPlace() {
            setLoadingIcons(true);
            var places = platform.getPlacesService(),
                entryPoint = H.service.PlacesService.EntryPoint,
                txtSearch = document.getElementById('txtSearch');
            places.request(entryPoint.SEARCH, { 'at': _HEREmap.getCenter().lat + ',' + _HEREmap.getCenter().lng, 'q': txtSearch.value, 'size': 5 }, function (response) {
                var items = response.results.items;
                var placeHTML = '<div><a href="#" onclick="return showMapForDistination({LAT}, {LNG});"> <input hidden name="lat" value="{LAT}"><input hidden name="lat" value="{LNG}">{TITLE} <img src="Images/navigation Icon.png" id="arr" width="15" /> </a></div>';
                var html = '';
                for (var i = 0; i < items.length; i++) {
                    html += placeHTML.replace("{TITLE}", items[i].title).replace("{LAT}", items[i].position[0]).replace("{LNG}", items[i].position[1]);
                }
                document.getElementById('divSearchResult').innerHTML = html + '<div id="divCnclBtn"><img src="Images/Cancel Button.png" id="cnclBtn" onclick="onSearchTextBlur();"></div>';
                document.getElementById('divSearchResult').style['display'] = 'block';
                setLoadingIcons(false);
            }, function (resp) {
                //console.log('ERROR: ' + resp);
                setLoadingIcons(false);
            });


        }

Upvotes: 0

Views: 97

Answers (1)

echom
echom

Reputation: 932

So, from what I can tell in the Places API reference, it's surprisingly hard to do...

First, instead of 'at' use 'in' with a bounding box (i.e. the bounding box of the country) to get rough filtering to work. When you get results, look at each place result's address property and filter them by address.country (or address.countryCode).

Upvotes: 1

Related Questions