【发布时间】:2015-12-17 17:16:49
【问题描述】:
我刚刚注册了Google Places API。他们发给我一个server key,我在我的代码中使用它。
这是我的代码:
function getLatLon($address)
{
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,'https://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($address));
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$json=curl_exec($curl);
curl_close($curl);
$json=json_decode($json);
$details=[
'lat'=>$json->results[0]->geometry->location->lat,
'lng'=>$json->results[0]->geometry->location->lng
];
return $details;
}
function getDetails($address)
{
$apikey='googlesuppliedapikey';
$locdetails=getLatLon($address);
$latitude=$locdetails['lat'];
$longitude=$locdetails['lng'];
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude,$longitude&key=$apikey');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$json=curl_exec($curl);
curl_close($curl);
$json=json_decode($json);
print_r($json);
}
$address='3342 Shawnee Avenue Avenue West Palm Beach, FL 33409';
getDetails($address);
纬度和经度功能工作正常。我的问题在getDetails function 内。
我目前的反应如下
stdClass Object
(
[error_message] => The provided API key is invalid.
[html_attributions] => Array
(
)
[results] => Array
(
)
[status] => REQUEST_DENIED
)
不太清楚是什么问题。我真的只是在 5 分钟前创建了这个 API 密钥。 我也尝试了昨天创建的先前密钥,它提供了相同的答案
无论如何感谢您的帮助。
【问题讨论】:
标签: php google-maps-api-3