只有第一个InfoWindow在Google Map上显示

时间:2015-01-29 16:34:21

标签: javascript angularjs google-maps google-maps-api-3

为什么只有第一个(仅限一个)InfoWindow在Google Map上显示?我希望所有固定地址都显示InfoWindow。

我已经搜索了Only the first marker showing on google mapGoogle Maps API InfoWindow only showing the first location for all the markersGoogle maps-api v3 InfoWindow automatically open on page load等答案,但仍然没有运气。

这是我的代码。

  $scope.initialise = function(){

    $http.get('http://remoteapi.com/' + $scope.name)
        .success(function(data) 
        {
            var myLatlng = new google.maps.LatLng(8.4844173, 124.6526134);
            var mapOptions = {
                center: myLatlng,
                zoom: 10,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map = new google.maps.Map(document.getElementById("map"), mapOptions);

            for( var i in data ) {
                var position = new google.maps.LatLng(data[i].lat, data[i].lon);

                marker = new google.maps.Marker({
                    position: position,
                    map: map,
                    content: data[i].description
                });

                var infowindow = new google.maps.InfoWindow({
                  content: "<img style='max-width:50px;max-height50px;' src='images/"+data[i].image+"'>"
                  });

            }

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

  };

  google.maps.event.addDomListener(document.getElementById("map"), 'load', $scope.initialise());

0 个答案:

没有答案