【问题标题】:Dynamically loaded Google Map API in Javascript: Click on marker popup在 Javascript 中动态加载的 Google Map API:单击标记弹出窗口
【发布时间】:2012-05-03 15:56:44
【问题描述】:

所以我有一张我正在处理的地图,像这样动态加载:

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'); ?>

目前它会这样做,但在警报中......

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

感谢您的帮助!

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 1970-01-01
      • 2019-02-01
      • 2013-05-16
      • 2020-06-03
      • 2013-04-27
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多