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 ?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.