Google Maps API自定义弹出窗口

Dre*_*ron 5 google-maps google-maps-api-3

我正在搞乱谷歌地图API,我似乎无法弄清楚如何在有人点击我添加的自定义地图图标后在地图中添加弹出信息.我正在使用的代码如下,示例在littlemarketbrasserie.com上

任何帮助将不胜感激.

<script type="text/javascript">
      function initialize() {
        var mapOptions = {
          zoom: 15,
          panControl: false,
          mapTypeControl: false,
          center: new google.maps.LatLng(41.89924, -87.62756),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(document.getElementById('map_canvas'),
                                      mapOptions);

        var image = 'img/lm-logo-maps1.png';
        var myLatLng = new google.maps.LatLng(41.89924, -87.62756);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            animation: google.maps.Animation.DROP,
            icon: image,
        });

        var styles = [
                  {
                    stylers: [
                      { hue: "#ff9f67" },
                      { saturation: -20 },
                      { gamma: 1.50 }
                    ]
                  },{
                    featureType: "road",
                    elementType: "geometry",
                    stylers: [
                      { lightness: 100 },
                      { visibility: "simplified" }
                    ]
                  },{
                    featureType: "road",
                    elementType: "labels.text.stroke",
                    stylers: [
                      { visibility: "off" }
                    ]
                  },

                  {
                    featureType: "water",
                    elementType: "geometry.fill",
                    stylers: [
                        { visibility: "on" },
                        { color: "#ffa066" },
                        { lightness: 80 }
                    ]
                    }
                ];

                map.setOptions({styles: styles});
      }
    </script>
Run Code Online (Sandbox Code Playgroud)

The*_*pha 6

如果你正在谈论infowindow那么你可以在你的initialize功能内部使用

var popup=new google.maps.InfoWindow({
    content: "Hello"
});
google.maps.event.addListener(marker, 'click', function(e) {
    // you can use event object as 'e' here
    popup.open(map, this);
});
Run Code Online (Sandbox Code Playgroud)

演示.

此外,如果你想添加的风格自定义infowindow,那么你可以看看这个这个例子中使用jQuery对话框.