2016-09-15 74 views
0

我在bootstrap主題中工作,我在添加google maps api時遇到了一些問題。地圖是在javascript文件,它是這樣的:如何在Google Maps JavaScript API中設置API密鑰?

google.maps.event.addDomListener(window, 'load', init); 

function init() { 

    var mapOptions = { 

     zoom: 15, 
     scrollwheel: false, 
     center: new google.maps.LatLng(41.428005, -8.674701), 

     styles: [ 
     { 
... 

    var mapElement = document.getElementById('map'); 

    var map = new google.maps.Map(mapElement, mapOptions); 

    var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(41.428005, -8.674701), 
     map: map, 

而在HTML中,只有這樣的:

<section class="map"> 
     <div id="map"></div> 
    </section> 

我怎麼能在這裏補充的Api關鍵?

謝謝。

+0

試用Google第一 –

+1

然後添加此<腳本類型= 「文本/ JavaScript的」 SRC =「http://maps.googleapis.com/maps/api/js?key=YOUR KEY &傳感器=假&圖書館=地方「> –

+0

我以前試過,它沒有工作。也許我在代碼上做錯了什麼。你能給我舉個例子嗎?對不起,我是新手,謝謝。 –

回答

1

當您在網站上包含腳本時,Google Maps API的關鍵字將作爲包含該URL的查詢參數。

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=API_KEY"></script> 
+0

它的工作。非常感謝你。 –