2016-09-01 15 views
3

我試圖使用Google Places API獲取某個地點的經度和緯度。GoogleApiClient未配置爲使用此通話所需的API

我下面這個例子:Google Directions Android

我配置客戶端這樣的:

mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addApi(Places.GEO_DATA_API) 
      .addApi(Places.PLACE_DETECTION_API) 
      .addApi(LocationServices.API) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .build(); 

但後來這裏:

PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi 
        .getPlaceById(mGoogleApiClient, placeId); 

我得到以下錯誤:

java.lang.IllegalArgumentException: GoogleApiClient is not configured to use the API required for this call. 

我該如何解決?

我在Google API控制檯上激活了API,我想我正在配置它,就像這個例子。

+0

您是否在清單文件中添加了正確的配置? https://developers.google.com/places/android-api/start –

+0

@MatiasElorriaga是的,我使用與Google地圖相同的API密鑰,並且地圖工作正常。 –

+0

你叫'mGoogleApiClient.connect();' –

回答

6

因此,在與@Daniel討論後,解決方案是使用兩個不同的GoogleApiClient實例:一個用於LocationServices API,另一個用於Places API。

相關問題