Display multiple markers on a map with their own info windows

后端 未结 5 1227
遥遥无期
遥遥无期 2021-01-20 17:12

I need to display multiple markers on a map, each with their own infowindow. I have created the individual markers without a problem, but don\'t know how to create the infow

5条回答
  •  被撕碎了的回忆
    2021-01-20 18:02

    I tried the code from Sean Vieira, I was struggling to get the infowindow show me same corresponding markers Info.

    If you have same problem try: Here we are setting info (you can keep any name ) and then latter will use it.

    var marker = new google.maps.Marker({
                map: map,
                position: myLatlng,
                title: _park.title,
                info :    _park.infoWindowContent,    // note info here  
                clickable: true,
            });  
    

    next see Content, so we are using the info we want to set to Marker

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

    This worked for me.

    Ref: https://tommcfarlin.com/multiple-infowindows-google-maps/

提交回复
热议问题