谷歌地图API与infowindow不工作

问题描述:

我想创建一个信息窗口打开与用户点击标记的地图。到目前为止,代码似乎没有工作,地图之前显示,但一旦我把信息窗口弹出窗口的代码不仅显示信息窗口,但地图也停止显示在我的网页上。下面的代码:谷歌地图API与infowindow不工作

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


     <script> 
     var map; 

      var markers=[]; 

     function initMap(){ 

      map= new google.maps.Map(document.getElementById('map'),{ 

       center:{ lat:40.7413549, lng:-73.9980244}, 
       zoom:13 
      }); 


     var locations=[ 


      {title:"Park Ave Penthouse",location:{lat:40.7713024,lng:-73.9632393}}, 
      {title:"Chelsea Loft", location;{lat:40.7444883,lng:-73.9949465}}, 
      {title:"Union Square Open Floor Plan",location:{lat:40.7347062,lng:-73.984377}}, 
      {title:"East Village Hip Studio",location:{lat:40.7281777,lng:-73.984377}}, 
      {title:"TriBeCa Artsy Bachelor Pad",location:{lat:40.7195264,lng:-74.0089934}},  
      {title:"Chinatown Homey Space",location:{lat:40.7180628,lng:-73.9961237}} 

     ]; 
      var largeInfowindow= new google.maps.InfoWindow(); 
      var bounds= new google.maps.LatLngBounds(); 


      for (var i=0; i< locations.lenght;i++){ 

       var position = locations[i].location; 
       var title = locations[i].title; 

       var marker= new google.maps.Marker({ 

        map: map, 
        position:position, 
        title:title, 
        animation:google.maps.Animation.Drop, 
        id:i 

        }); 

        markers.push(marker); 
        bounds.extend(marker.position); 
        marker.addListner ("click",function(){ 

        populateInfoWindow(this,largeInfowindow); 




      }); 

      map.fitBounds(bounds); 






       }; 

       markers.push(marker); 

       markers.addListner("click",function(){ 

        populateInfoWindow(this,largeInfoWindow); 
       }); 


       } 



      function populateInfoWindow (marker, infowindow){ 


       if(infowindow.marker=!marker){ 

        infowindow.marker= marker; 
        infowindow.setContent("<div>"+marker.title+"</div>"); 

        infowindow.open(map,marker); 

        infowindow.addListner("closeclick",function(){ 


         infowindow.setMarker(null); 
        }); 






       } 

      } 


<script async defer 
       src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAvrWT4KKcsDSSGYXpxRry3m7j90pPjZgA&v=3&callback=initMap"></script> 
+0

请检查控制台的脚本错误。 –

+0

我得到一个JavaScript错误与张贴的代码:'未捕获的SyntaxError:意外的标记;'在这个'标题:“切尔西阁楼”, 位置; { 纬度:40.7444883, LNG:-73.9949465 }' – geocodezip

+0

然后'遗漏的类型错误:markers.addListner不是function' – geocodezip

的错误是在这一行:

if(infowindow.marker=!marker){ //it is "!=" and not "=!" 

始终为JavaScript错误检查控制台。 infowindow代码之后,你甚至无法看到这意味着你有JavaScript错误的毛。