在Javascript中动态加载Google Map API:点击标记弹出窗口

时间:2012-04-23 01:27:46

标签: api google-maps google-maps-markers markerclusterer

所以我有一张我正在动态加载的地图,如下所示:

foreach( $myposts as $post ) :  setup_postdata($post); ?>                                

    var marker<?php echo $count; ?> = new google.maps.Marker({ position: new google.maps.LatLng<?php the_field('longlat'); ?>, map: map, title:"<?php the_title(); ?>, <?php the_field('address'); ?>", icon:image });

    google.maps.event.addListener(marker<?php echo $count; ?>, 'click', function()
    {

        alert('you clicked: <?php the_title(); ?> - <?php the_field('address'); ?>');

    });

    <?php $count++ ?>

    <?php endforeach; ?>

我想要它做的是优雅地加载带有标题和地址的标记弹出窗口......来自php的这两个值:

<?php the_title(); ?> - <?php the_field('address'); ?>

目前它会这样做,但是发出警报......

那么如何设置它以使它出现在标记上方的弹出窗口中?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我建议您查看infoWindow课程及相关文档:https://developers.google.com/maps/documentation/javascript/reference#InfoWindow

还有相关的代码示例: https://developers.google.com/maps/documentation/javascript/demogallery

如果您有警报代码,可以输入以下内容:

var infowindow = new google.maps.InfoWindow();
infowindow.setContent('Whatever you want in the popup');
infowindow.open(map, this);