Marker content (infoWindow) Google Maps

前端 未结 2 1406
傲寒
傲寒 2020-12-07 20:53

I\'m trying to add infoWindow\'s to multiple markers on a Google Map. The closest I have come is to get an infoWindow to display the last address you can see in the array, o

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 21:22

    Although this question has already been answered, I think this approach is better : http://jsfiddle.net/kjy112/3CvaD/ extract from this question on StackOverFlow google maps - open marker infowindow given the coordinates:

    Each marker gets an "infowindow" entry :

    function createMarker(lat, lon, html) {
        var newmarker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lon),
            map: map,
            title: html
        });
    
        newmarker['infowindow'] = new google.maps.InfoWindow({
                content: html
            });
    
        google.maps.event.addListener(newmarker, 'mouseover', function() {
            this['infowindow'].open(map, this);
        });
    }
    

提交回复
热议问题