I am using the Google Places Web Service API to roll my own autocomplete functionality.
https://developers.google.com/places/web-service/autocomplete
I'm using JS to fetch a server-side request that I make using PHP.
<?php
header('Content-Type: application/json; charset=utf-8');
$api = 'https://maps.googleapis.com/maps/api/place/autocomplete/json';
$key = 'api-key-goes-here'; // Use your own API key here.
$input = 'London'; // A hard-coded example.
$requestPath = "{$api}?&key={$key}&input={$input}";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $requestPath,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$data = ($err) ? $err : $response;
echo $data;
?>
All this works great and I get back a correct JSON response.
However, I am getting results from a global search, when Ideally I'd like to restrict it to UK / GB only.
For example, in the above code, the search for 'London' returns a London in Canada and elsewhere. How can I restrict this? I don't see anything mentioned in the documentation about being able to do this.
Many thanks for your help!