简体   繁体   English

没有来自Google Places文字搜寻API的回应

[英]No responses from google places text search api

I am getting no responses from google places text search API 我没有收到Google Places文本搜索API的回复

Here is my php code : 这是我的PHP代码:

$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(); 您缺少$ch = curl_init();

And I guess your $string should be named $city . 而且我猜您的$string应该命名为$city Also, use urlencode on $city . 另外,在$city上使用urlencode See Why should I use urlencode? 请参阅为什么我应该使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM