php get google place details from business name

Viewed 2074

I want to pull business data from google places ip. I can do that by using place_id with the code below;

$name = urlencode('Business name');
$place_id = 'XXXXXXXXXXXXXXXX';
$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid='.$place_id.'&key=XXXXXXXXXXXXXXXXX';
$json = file_get_contents($url);
$jsonContent = json_decode($json, TRUE);

$jsonContent['result']['name'];
$jsonContent['result']['formatted_phone_number'];
$jsonContent['result']['formatted_address'];
$jsonContent['result']['website'];
$jsonContent['result']['place_id'];

What I want to be able to do is the get business data using business name or get place_id by using business name so i can use the code above to pull the data. Obtaining the the place id with business name is possible on the following link;

Google place ID finder

Can anyone help with how i can obtain either business data using business name or obtain place id using business name?

1 Answers

If your businesses have unique names, you can use web API for that.

$url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=5000&name=BestBusiness&key=YOUR_API_KEY';
$json = file_get_contents($url);
$data = json_decode($json);

Get id out of $data and enjoy it.

Related