2016-01-29 38 views
0

我試圖讓一個應用程序的方向,但我不斷收到一個REQUEST_DENIED,我使用this answer提到的庫(在這裏is the repo在谷歌地圖REQUEST_DENIED的Android

我有API密鑰和我像這樣使用它:

GoogleDirection.withServerKey(getString(R.strings.google_maps_key)) 
    .from(new LatLng(40.2085, -3.7136)) 
    .to(new LatLng(mCoord[0], mCoord[1])) 
    .avoid(AvoidType.FERRIES) 
    .avoid(AvoidType.HIGHWAYS) 
    .execute(new DirectionCallback() { 
      @Override 
      public void onDirectionSuccess(Direction direction) { 
       if (direction.isOK()) { 
        Toast.makeText(getApplicationContext(), "DIRECTION KOK", Toast.LENGTH_LONG).show(); 
        //       direction. 
       } else { 
        Toast.makeText(getApplicationContext(), direction.getStatus(), Toast.LENGTH_LONG).show(); 
       } 
      } 

      @Override 
      public void onDirectionFailure(Throwable t) { 
       Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_LONG).show(); 
      } 
     }); 

我對什麼是失敗沒有任何線索。

回答

1

我發現了這個問題。這是我第一次使用谷歌控制檯開發者,我以爲我只需要API密鑰。原來你必須激活Google Direction API

現在請求是正確的。

0

在很多地方搜索後,我找到了我需要的答案。

就像你說的elbaulp,我們必須在谷歌地圖JavaScript API的幫助下啓用Google方向API,並且如果您要在地圖上添加特定位置,則必須激活Google Places API Web服務。

啓用我們需要的每個API非常重要。

感謝您的解決方案。

來自阿根廷的問候。

+1

嗨,你不應該發表評論作爲答案。如果我的答案解決了你的問題,你應該投票。很高興我的解決方案也適合你。 – elbaulp