2017-04-27 162 views
-1

我的Javascript和API密鑰有問題。我只想讓這段代碼在瀏覽器中顯示地圖,但它仍然找不到API KEY。Google Maps API V3 API密鑰無法加載

我以前用過幾次谷歌地圖,但我沒有這些問題。

我希望你能幫助我!

這裏是我的代碼

<!DOCTYPE html> 
<html> 
<head > 

    <title>maps</title> 
    <style type="text/css"> 
     body { 
      height: 100%; 
      margin: 0; 
      padding: 0 
     } 
    </style> 
</head> 
<body> 



<!-- Load the Google API: --> 

<script src="http://maps.googleapis.com/maps/api/js"></script> 

<script> 
var map = {};  
var mapCenter = new google.maps.LatLng(51.0, 1.5); 
var trackList = []; 
var trackSymbolSize = 1.0; 

var MAX_NUMBER_OF_TRACKS = 100000; 
var EXCEPTION_AT_LOGICAL_ERROR = true; 
var CONSOLE_LOG = true; 

function initMap() { 
    var mapProp = { 
     center: mapCenter, 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 


    document.getElementById("googleMap").style.height = innerHeight + 'px'; 
    document.getElementById("googleMap").style.width = innerWidth + 'px'; 

    map = new google.maps.Map(document.getElementById("googleMap"), mapProp); 
} 

function browserResize() { 
    document.getElementById("googleMap").style.height = innerHeight + 'px'; 
    document.getElementById("googleMap").style.width = innerWidth + 'px'; 

    google.maps.event.trigger(map, 'resize'); 
} 

</script> 

<script> 

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

</script> 

<div id="googleMap"></div> 

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDuZVG0Z9Ei7ubm5bkAfPsYUI-Wm8C_c-0&callback=initMap" async defer></script> 

</body> 

</html> 
+2

除去上'',因爲它已經與密鑰 –

+1

下面包括它似乎我說你已經包含了地圖API API兩次,一個沒有鍵(在頂部),也許第二次它不重新加載它? – masadwin

+0

做什麼@ Deep3015說....做它! – masadwin

回答

1

嘗試這樣的。

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 

 
    <title>maps</title> 
 
    <style type="text/css"> 
 
    body { 
 
     height: 100%; 
 
     margin: 0; 
 
     padding: 0 
 
    } 
 
    </style> 
 
    <!-- Load the Google API: --> 
 

 
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDuZVG0Z9Ei7ubm5bkAfPsYUI-Wm8C_c-0&callback=initMap" async defer></script> 
 
</head> 
 

 
<body> 
 
    <div id="googleMap"></div> 
 
    <script> 
 
    var map = {}; 
 
    var mapCenter 
 
    var trackList = []; 
 
    var trackSymbolSize = 1.0; 
 

 
    var MAX_NUMBER_OF_TRACKS = 100000; 
 
    var EXCEPTION_AT_LOGICAL_ERROR = true; 
 
    var CONSOLE_LOG = true; 
 

 
    function initMap() { 
 
     mapCenter = new google.maps.LatLng(51.0, 1.5); 
 
     var mapProp = { 
 
     center: mapCenter, 
 
     zoom: 8, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
     }; 
 

 

 
     document.getElementById("googleMap").style.height = innerHeight + 'px'; 
 
     document.getElementById("googleMap").style.width = innerWidth + 'px'; 
 

 
     map = new google.maps.Map(document.getElementById("googleMap"), mapProp); 
 
    } 
 

 
    function browserResize() { 
 
     document.getElementById("googleMap").style.height = innerHeight + 'px'; 
 
     document.getElementById("googleMap").style.width = innerWidth + 'px'; 
 

 
     google.maps.event.trigger(map, 'resize'); 
 
    } 
 
    </script> 
 

 

 
</body> 
 

 
</html>

+0

是的,這是它,它的作品:) Thnak你非常! – Hans