How to set a popup on markers with Google Maps API?

后端 未结 4 442
小鲜肉
小鲜肉 2021-02-01 18:09

I have this code where I display and set all my markers. How can I add a popup with some information on markers with this code? I add \"i\" variable on text, but it sets on all

4条回答
  •  天涯浪人
    2021-02-01 18:49

    this is the area where you can add your content of popup

    var infowindow = new google.maps.InfoWindow({
                    content: "Add your popup content here"
                  });
    

    and this is for showing your popup

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

    Below code shows how its work and use.

    features.forEach(function(feature) {
              var infowindow = new google.maps.InfoWindow({
                        content: "Add your popup content here"
                      });
                var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat,long),
                icon: "image.png",
                /*icon: icons[feature.type].icon,*/
                title: "Title for marker",
                map: map
              });
              marker.addListener('click', function() {
              infowindow.open(map, marker);
            });
            });

提交回复
热议问题