我有一个网站正在开发中,它使用 Google Maps API V3 来加载多个位置标记。一切正常,除了在 IE7/8 中,由于以下错误,我在数组中循环失败:
SCRIPT5007: Unable to get value of the property '5': object is null or undefined
我查看了 StackOverflow 上所有类似的问题,但找不到任何解决方案。
所以我试图从一个对象数组访问数据(我也尝试了一个嵌套数组,但出现了同样的错误)。我的数组如下。我也曾尝试删除 html 对象以防出现问题,但没有任何变化 - IE7/8 仍然无法获取对象值。
var sites = [
{title: "Hermitage Medical Clinic", latitude: 53.3593139774, longitude: -6.40494071541, enumerator: 1, html: "<div class=\"find_a_surgeon_info_inner\"><h4 style=\"margin: 0; padding: 0;\">Hermitage Medical Clinic</h4><p>Old Lucan Road, Dublin 20</p><p><a href=\"http://devel.pixelapes.com/iaps.ie/location/hermitage-medical-clinic/\">View hospital details</a></p></div>", iconTerm: "hospital" }
];
这是我尝试访问数据的函数:
function setMarkers(map, sites) {
for (var i = 0; i < sites.length; i++) {
// var sites = markers[i];
var icon = '<?php bloginfo("template_url"); ?>/images/map-icons/' + sites[i].iconTerm + '.png';
var siteLatLng = new google.maps.LatLng(sites[i].latitude, sites[i].longitude);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
icon: icon,
title: sites[i].title,
zIndex: sites[i].enumerator,
html: sites[i].html
});
var contentString = "Some content";
google.maps.event.addListener(marker, "click", function () {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
}
}
我也尝试过仅使用默认 map 标记,以防 iconTerm 对象出现特定问题,但 IE7/8 无法尝试获取下一个对象值。
这是发生这种情况的页面: http://devel.pixelapes.com/iaps.ie/surgeon/eamon-s-beausang/
奇怪的是,我有另一个 map 实例,其中我没有使用 map.fitBounds 设置边界。获取对象值的失败仍然发生,但 map 加载类型(但非常困惑):http://devel.pixelapes.com/iaps.ie/find-a-hospital-or-clinic/
我已尝试删除单个外科医生页面上的 fitBounds 功能,但 map 仍然无法像在“查找医院” map 上那样部分加载。
关于如何解决这个问题有什么想法吗?
最佳答案
在 sites
和 latlngs
的最后一项后面有尾随逗号,删除它们,IE 不喜欢数组/对象中的尾随逗号。
关于javascript - IE7/8 javascript "SCRIPT5007: Unable to get value of the property",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10430460/