我的javascript出错了。这是一个从tr表中获取坐标的脚本。我认为这与我的听众有关,但我不确定。什么都行不通..
有人知道错误的存在吗?
<script type='text/javascript'>
var infowindow = new google.maps.InfoWindow();
var markers = [];
function init_map() {
var myOptions = {
zoom: 7
, center: new google.maps.LatLng(51.452928, 4.789983)
, mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);
$('table tr').each(function (idx, item) {
var coordsStr = $(this).find(".coords").html();
if (!coordsStr) return;
createMarker($(this));
});
$('a').click(function (evt) {
var coordsStr = $(this).parents().find(".coords").html();
var coords = coordsStr.split(",");
var point = new google.maps.LatLng(coords[0], coords[1]);
map.setCenter(point);
google.maps.event.trigger(markers[coordsStr], 'click');
});
google.maps.event.trigger(markers["52.939347, 4.754741"], 'click');
}
function createMarker(jqe) {
var coordsStr = $(jqe).find(".coords").html();
console.log(coordsStr);
coords = coordsStr.split(",");
var point = new google.maps.LatLng(coords[0], coords[1]);
var marker = new google.maps.Marker({
map: map
, position: point
});
var content = jqe.find("td").eq(0).html(); + '<br>'
var content1 = '<strong></strong><br>'+jqe.find("td").eq(2).html(); + '<br>'
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(content+content1);
infowindow.open(map, marker);
});
markers[coordsStr] = marker;
}
google.maps.event.addDomListener(window, 'load', init_map);
</script>