2017-01-06 202 views
1

有一個谷歌地圖API密鑰.. AdfadXXXXXXXXXXX ....我如何添加谷歌地圖API密鑰EGamp在警予

我已經安裝了EGamp擴展。我如何在下面的代碼中爲本地主機和生產設置Api密鑰。

我嘗試使用$gMap->setAPIKey('local.mylocal.com','MYAPYKEY');功能EGMAP,但沒有工作..

仍然在控制檯它顯示的是「谷歌地圖API的警告:NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys」。

以下是我的代碼。

Yii::import('vendor.2amigos.egmap.*'); 
      $gMap = new EGMap(); 
      $gMap->zoom = 16; 
      $gMap->mapTypeControl = false; 
      $gMap->scrollwheel = false; 

      $gMap->setContainerStyle('width', '100%'); 
      $gMap->setContainerStyle('height', '250px'); 
      $gMap->setCenter($defaultVenue->lat, $defaultVenue->lng); 

      // Create GMapInfoWindows 
      $infoWindow = new EGMapInfoWindow('<div>' . nl2br($defaultVenue->full_address) . '</div>'); 

      // Create marker 
      $marker = new EGMapMarker($defaultVenue->lat, $defaultVenue->lng, ['title' => $defaultVenue->full_address]); 
      $marker->addHtmlInfoWindow($infoWindow); 
      $gMap->addMarker($marker); 

我可以爲本地主機和生產使用相同的密鑰嗎?

+0

耶之前添加$gMap->setAPIKey(DOMAIN, APIKEY)。我有同樣的問題。但是我沒有在代碼中看到你的'setAPIKey' –

回答

1

幾個月前使用此擴展。不知道在閱讀文檔時我是否錯過了一些東西,但是我做了什麼被黑了一點,以使其起作用。在您的EGMap.php更改代碼以這個...

public function registerMapScript($afterInit=array(), $language = null, $region = null, $position = CClientScript::POS_LOAD) 
    { 
      // TODO: include support in the future 
      //$params = 'sensor=false'; 
      $params = ''; 

      $key = $this->getAPIKey(); 

      if ($language !== null) 
       $params .= '&language=' . $language; 
      if ($region !== null) 
       $params .= '&region=' . $region; 

      //hack!! 
      if ($key !== null) 
       $params .= '&key='. $key; 
      //end of hack 


      CGoogleApi::init(); 
      CGoogleApi::register('maps', '3', array('other_params' => $params)); 

      .... 
      .... 
      .... 
      .... 
    } 

在您看來,不要忘記你的$gMap->renderMap();

希望的作品