簡體   English   中英

Google Places API網絡服務API密鑰無效

[英]Google Places API Web Services API Key Invalid

我剛剛注冊了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密鑰。 我也嘗試了昨天創建的先前密鑰,它提供了相同的答案

無論如何,謝謝您的幫助。

您的請求網址不正確。

文檔中

地點詳細信息請求

地點詳細信息請求是以下格式的HTTP URL:

https://maps.googleapis.com/maps/api/place/details/output?參數 ,其中輸出可能是以下值之一:

json (推薦)指示以JavaScript對象表示法(JSON)輸出。xml指示以XML輸出。發起搜索請求需要某些參數。 按照URL中的標准,所有參數都使用&字符分隔。 以下是參數及其可能值的列表。

密鑰 (必填)-您的應用程序的API密鑰。 該密鑰用於配額管理的目的是標識您的應用程序,以便使從應用程序添加的位置立即可用於您的應用程序。 訪問Google Developers Console創建一個API項目並獲取您的密鑰。 占位符或參考(您必須提供其中之一,但不能同時提供):placeid-從位置搜索返回的唯一標識位置的文本標識符。 有關位置ID的更多信息,請參見位置ID概述。 reference(參考)—從位置搜索返回的唯一標識位置的文本標識符。 注意:現在不推薦使用引用,而推薦使用placeid。 請參閱此頁上的棄用通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM