【发布时间】:2013-12-13 15:06:08
【问题描述】:
我使用谷歌地图创建了一个地图,该地图显示效果很好,并显示了我想要的所有标记,但是点击事件没有触发,我不明白为什么我将脚本从初始化函数中更改为文档在 Jquery 中准备好并再次恢复,因为它没有任何区别我将整个脚本从标题部分移动到没有区别的正文底部。
我不知道出了什么问题,我想在单击标记时用一些文本填充地图一侧的 div。
感谢您的帮助,我会把它放在一个 fork 上,但为了让它工作,它会为 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>
【问题讨论】:
标签: google-maps