【问题标题】:No responses from google places text search apigoogle 地方文本搜索 api 没有响应
【发布时间】:2015-08-23 21:06:29
【问题描述】:

我没有收到来自 google 地方文本搜索 API 的响应

这是我的 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);

它甚至没有给出以下结果

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

我做错了什么,我该如何解决?

【问题讨论】:

  • 哦,太好了,您发布了您的 API 密钥。顺便说一句,您是否正确编码了您的$city
  • 您在查询参数中传递了“$city”,但您似乎还没有定义。
  • @WisdmLabs 不错!
  • 为了安全起见,您也可以考虑通过urlencode() 运行您的字符串。否则可能会导致 URL 损坏。

标签: php mysql curl xampp


【解决方案1】:

你不见了$ch = curl_init();

我猜你的$string 应该命名为$city。另外,在$city 上使用urlencode。见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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多