No responses from google places text search api

333 views Asked by At

I am getting no responses from google places text search API

Here is my php code :

$string=$row["PropertyTitle"].'+'.$row["LocalityName"].'+'.$row["CityName"];
$details_url="https://maps.googleapis.com/maps/api/place/textsearch/json?query=".$city."&key=someapikey";
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$geoloc = json_decode(curl_exec($ch), true);
print_r($geoloc);

it does not even give the below result

{ 
    "html_attributions" : [],
    "results" : [],
    "status" : "INVALID_REQUEST"
}

What is the mistake i am doing and How can i fix this ?

1

There are 1 answers

0
Rene Korss On

Your are missing $ch = curl_init();

And I guess your $string should be named $city. Also, use urlencode on $city. See Why should I use urlencode?.

<?php
$city = urlencode( $row["PropertyTitle"].'+'.$row["LocalityName"].'+'.$row["CityName"] );
$details_url="https://maps.googleapis.com/maps/api/place/textsearch/json?query=".$city."&key=API_KEY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$geoloc = json_decode(curl_exec($ch), true);
print_r($geoloc);