2011-02-08 1 views
2

Google Map api (v3) 및 InfoWindows에 첨부 된 마커의 클릭 이벤트가 열리지 않는 문제가 있습니다. 자바 스크립트를 디버깅 할 때 마커 및 InfoWindow가 올바르게 생성 된 것처럼 보이므로 클릭 이벤트 리스너를 추가 할 때 잘못된 동작을하고 있다고 가정합니다.Google지도 InfoWindow가 클릭 이벤트에서 열리지 않음

다음은 마커 추가 등이 발생하는 곳입니다. 누구든지 문제가 무엇인지 알 수 있습니까? 어떤 제안에 대한

$.post("/Club/SearchClubsByLocation", { latitude: searchLat, longitude: searchLng }, 
      function (clubs) { 
       $.each(clubs, function (i, club) { 
        var LL = new google.maps.LatLng(club.Latitude, club.Longitude); 
        pointArray.push(LL); 

        var infoWindow = new google.maps.InfoWindow({ 
         content: club.ClubName + " HELLO!!!" 
        }); 

        var marker = new google.maps.Marker({ 
         map: map, 
         position: LL 
        }); 

        google.maps.event.addListener(marker, 'click', function() { 
         infowindow.open(map, marker); 
        }); 

        markerArray.push(marker); 
       }); 

       for (i in pointArray) { 
        bounds.extend(pointArray[i]); 
       } 

       map.fitBounds(bounds); 
       pointArray = []; 
      }, 
      "json" 
     ); 

감사합니다,

리치

답변

10

마침내 정보창을 만들고을 열 마커에 클릭 리스너를 추가 후 기능 이외의 기능을 갖는하여 그것을 해결 여기

와 같이 여러 정보창을 추가하기 위해 별도의 기능을해야 할 것 같다

$.post("/Club/SearchClubsByLocation", { latitude: searchLat, longitude: searchLng }, 
    function (clubs) { 
    $.each(clubs, function (i, club) { 
     var LL = new google.maps.LatLng(club.Latitude, club.Longitude); 
     pointArray.push(LL); 

     var marker = new google.maps.Marker({ 
     map: map, 
     position: LL 
     }); 

     addInfoWindow(marker, club.ClubName); 

     markerArray.push(marker); 
    }); 

    for (i in pointArray) { 
     bounds.extend(pointArray[i]); 
    } 

    map.fitBounds(bounds); 
    pointArray = []; 
    }, 
    "json" 
); 

function addInfoWindow(marker, content) { 
    var infoWindow = new google.maps.InfoWindow({ 
     content: content 
    }); 

    google.maps.event.addListener(marker, 'click', function() { 
     infoWindow.open(map, marker); 
    }); 
} 

정보창

Event Closures

건배

리치에게 답변을 게시

+0

감사합니다! 그것은 나를 많이 도왔다. –

+0

안녕하세요. 나는 비슷한 문제에 직면하고 있지만 당신의 솔루션을 시도했지만 unfortunatelly 그것이 작동하지 않습니다. 좀 봐 줄래? [내 질문은 여기에 있습니다] (http://stackoverflow.com/questions/35456293/google-map-infowindow-not-opening). 많은 감사합니다! –