2015-10-20 200 views
0

我正在使用此代码来生成谷歌地图使用谷歌地图API。 这是工作示例jsfiddle谷歌地图api不加载地图

js代码

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

function initialize() { 
    var myloc = new google.maps.LatLng(35.433820, -97.135620); 
    var mapOptions = { 
     zoom: 17, 
     topCenter: myloc, 
     scrollwheel: false 
    }; 
    var map = new google.maps.Map(document.getElementById('map'),mapOptions); 
    var marker = new google.maps.Marker({ 
     position: map.getCenter(), 
     map: map, 
     animation: google.maps.Animation.BOUNCE 
    }); 
    var contentString = '<div id="content" style="dir:rtl; text-align:right;">'+ 
      '<div id="siteNotice">'+ 
      '</div>'+ 
      '<h1 id="firstHeading" class="firstHeading"><h1>title here</h1>'+ 
      '<div id="bodyContent">'+ 
      '<p>description here</p>'+ 
      '</div>'+ 
      '</div>'; 
    var infowindow = new google.maps.InfoWindow({ 
     content: contentString, 
     maxWidth: 250 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.open(map,marker); 
    }); 
} 
google.maps.event.addDomListener(window, 'load', initialize); 

HTML代码

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

地图iframe是有,但映射为空,没有标记没有道路就在iframe

+0

为什么这个标签[谷歌地图的API-2](http://stackoverflow.com/questions/tagged/google -maps-api-2),该版本的API自2010年5月19日起正式被弃用。 – geocodezip

回答

3

地图需要center -option(您已设置topCenter-选项)。 此外,你应该加载API的发布版本,目前的实验版本是非常错误的。

https://jsfiddle.net/doktormolle/h9q2ncnx/2/

+0

非常感谢您的帮助 –

2

如果您改变topCenter参数中心参数它工作