谷歌地图标记上的点击事件未触发

时间:2013-12-13 15:06:08

标签: google-maps

我使用google地图创建了一个地图,显示效果很好并显示了我想要的所有标记,但是click事件没有触发,我看不出为什么我将脚本从初始化函数更改为文档准备好在Jquery中再次恢复,因为它没有任何区别我将整个脚本从标题部分移动到正文的底部,没有任何区别。

我不知道是什么问题,我想填充一个div,当点击标记时,div会在地图的一侧显示一些文字。

感谢任何帮助,我会把它放在一个分叉上,但为了它工作,它会对xml文件进行ajax调用。

 <script type="text/javascript">
    function initialize()
    {
    var iconBase = 'https://dl.dropboxusercontent.com/u/102059869/'; //public drop box for icons
    var latlng = new google.maps.LatLng(53.74,-2);//centres map around hull
    var myOptions = {zoom: 8,center: latlng,mapTypeId: google.maps.MapTypeId.ROADMAP};   
    var map = new google.maps.Map(document.getElementById("map"), myOptions);// Creates Map
    var mylatlng = new google.maps.LatLng(53.745670900000000000,-0.336741299999971500);
    var marker = new google.maps.Marker({position: mylatlng,map: map,title: 'Kingstown',  icon: iconBase + 'Kingstown_Logo.png'});// Creates Marker

            //Creates markers from data       
            $.get('PHP/SQL_MainData.php', function(d){
            $(d).find("marker").each(function()
                {
                    var latlng = new google.maps.LatLng($(this).attr('latitude'),$(this).attr('longitude')); //gets Google LatLng
                    var myMarker = new google.maps.Marker(
                            {position: latlng,
                              map: map,
                              title:$(this).attr('traffic'),
                              icon: iconBase + 'caution.png'
                            }); 

                  marker.info = new google.maps.InfoWindow({content: '<b>Info:</b> ' + $(this).attr('traffic')});

                 });
            });

            google.maps.event.addListener(marker, 'click', function() {
                        marker.info.open(map, marker);
                        $('#info-area span').text(marker.info);
                        });   
      }         
</script>

1 个答案:

答案 0 :(得分:0)

google.maps.Marker是&#34; myMarker&#34;

您正在将标记添加到标记(不是google.maps.Marker)。

                var latlng = new google.maps.LatLng($(this).attr('latitude'),$(this).attr('longitude')); //gets Google LatLng
                var myMarker = new google.maps.Marker(
                        {position: latlng,
                          map: map,
                          title:$(this).attr('traffic'),
                          icon: iconBase + 'caution.png'
                        }); 

              marker.info = new google.maps.InfoWindow({content: '<b>Info:</b> ' + $(this).attr('traffic')});

             });
        });

        google.maps.event.addListener(myMarker, 'click', function() {
                    marker.info.open(map, myMarker);
                    $('#info-area span').text(marker.info);
                    });   
相关问题