簡體   English   中英

沒有來自Google Places文字搜尋API的回應

[英]No responses from google places text search api

我沒有收到Google Places文本搜索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"
}

我在做什么錯誤?該如何解決?

您缺少$ch = curl_init();

而且我猜您的$string應該命名為$city 另外,在$city上使用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