簡體   English   中英

為什么Google Map無法在JavaScript中加載?

[英]why google map not load in javascript?

我正在執行此鏈接中給出的步驟https://developers.google.com/maps/documentation/javascript/tutorial加載后出現錯誤,您能告訴我哪里錯了嗎? 我已經生成了密鑰? 小提琴http://jsfiddle.net/p3kcztvb/1/

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map-canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATC35pv00Ga3hRxP4t5W7NtM9as48PGVQs">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas"/>
  </body>
</html>

以下錯誤說明了自己。

"provided key is not a valid Google API Key,"

產生正確的金鑰

To create your API key:

    Visit the APIs Console at https://code.google.com/apis/console and log in with your Google Account.
    Click the Services link from the left-hand menu.
    Activate the Google Maps JavaScript API v3 service.
    Click the API Access link from the left-hand menu. Your API key is available from the API Access page, in the Simple API Access section. Maps API applications use the Key for browser apps. 

這里

圖片在這里

標記代碼如下:

// Adds a marker with popup window information
  var marker1Latlng = new google.maps.LatLng(35.65654,-106);
  var contentString1 = 'I love New Mexico! <a href="http://www.newmexico.org">More</a> about the Land of Enchantment';
  var infowindow = new google.maps.InfoWindow({
      content: contentString1
  });
  var marker1 = new google.maps.Marker({
      position: marker1Latlng,
      map: map,
      title: 'New Mexico'
  });
  google.maps.event.addListener(marker1, 'click', function() {
    infowindow.open(map,marker1);
  });
//End of Add Marker code

嗨,Fiddle的Kanika似乎您使用的API密鑰無效。 您可能需要從Google控制台重新生成Google Maps API Engine的API密鑰。

更改此代碼行-基本上,這里不需要api鍵

<script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATC35pv00Ga3hRxP4t5W7NtM9as48PGVQs">
    </script>

用。。。來代替

 <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?v=3.exp">
    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM