Places API with countries

I am trying to limit searches by country. If I use the search data below I get no results, but if remove the countries = ‘GB’ the search returns the correct result. I am trying to limit as the place search returns the wrong result if people put a county in the search so I want to limit strings ending in UK, England etc to the United Kingdom.

data
array(4) {
[“query”]=>
string(9) “ilminster”
[“language”]=>
string(2) “GB”
[“hitsPerPage”]=>
int(12)
[“countries”]=>
string(2) “GB”
}

text
string(9) “ilminster”

{“result”:“not_found”}

Hi @janetaubman,

can you share the full request (in curl for example)?

I tried with the exact same parameters you provided but cannot reproduce your results:

https://codepen.io/team/algolia/pen/OgbdLg

I am using your php client.

The code is as follows

        $countries  = 'GB';
        $url = 'https://places-dsn.algolia.net/1/places/query';
        if ( $action == 'geocode' ) {
											$data = ( array( 'query' => $text, 'language' => 'GB', 'hitsPerPage' => 1 ) );
							}
							else {
											$data = ( array( 'query' => $text, 'language' => 'GB' , 'hitsPerPage' => 12 ) );
							}
							}
        if ($countries != '') { $data['countries'] = $countries;}
$client = new \AlgoliaSearch\Client("xxx", "xxx");
$client->setForwardedFor($ip);
$places = $client->initPlaces(xxx', "xxx");

$message = $places->search($text,$data);

Alright, I think I isolated the issue.

Replace:
$countries = 'GB';
by
$countries = 'gb';

This is a bug on our end, it shouldn’t be case sensitive. I will open an issue in the project.

Let me know if it solved your issue!

That fixed it. Can I just check does the language setting also need to be in lowercase?

Awesome!

Yes it must be lowercase as well. It seems to work because english is the default lang, but the behaviour is undefined.

1 Like