我正在使用Google地图以在地图上显示标记。我在Google Maps的实用程序库1.1版中使用了Markermanager(http://gmaps-utility-library-dev.googlecode.com/svn/tags/markermanager/1.1/src/markermanager.js)
该脚本在Firefox,Chrome和Opera中运行良好,但在IE7和IE8中,地图显示没有标记。 IE给了我一个错误:
'posn.0'为空或无对象 googlemaps.js 代码:0 URI:mydomain.com/googlemaps.js
Googlemaps.js看起来像:
var officeLayer = [
{
"zoom": [0, 1],
"places": [
{
"name": "USA",
"posn": [40.72, -73.9826]
},
{
"name": "Europe",
"posn": [52.370, 4.8966]
}
]
},
{
"zoom": [2, 17],
"places": [
{
"name": "Amsterdam",
"posn": [52.370, 4.8966]
},
{
"name": "Barcelona",
"posn": [41.388, 2.1833]
},
{
"name": "Berlin",
"posn": [52.5166, 13.4000]
},
{
"name": "New York City",
"posn": [40.72, -73.9826]
},
{
"name": "Paris",
"posn": [48.860, 2.3333]
}
]
},
{
"zoom": [9, 17],
"places": [
{
"name": "&klevering Centraal",
"posn": [52.379446, 4.893913]
},
{
"name": "290 Square Meters",
"posn": [52.368906, 4.902288]
}
]
}
];
var map;
var mgr;
var icons = {};
var allmarkers = [];
function getIcon(images) {
var icon = null;
if (images) {
if (icons[images[0]]) {
icon = icons[images[0]];
} else {
icon = new GIcon();
icon.image = "img/"
+ images[0] + ".png";
var size = iconData[images[0]];
icon.iconSize = new GSize(size.width, size.height);
icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
icon.shadow = "img/"
+ images[1] + ".png";
size = iconData[images[1]];
icon.shadowSize = new GSize(size.width, size.height);
icons[images[0]] = icon;
}
}
return icon;
}
function setupOfficeMarkers() {
allmarkers.length = 0;
for (var i in officeLayer) {
var layer = officeLayer[i];
var markers = [];
for (var j in layer["places"]) {
var place = layer["places"][j];
var icon = getIcon(place["icon"]);
var title = place["name"];
var posn = new GLatLng(place["posn"][0], place["posn"][1]);
var marker = createMarker(posn,title,icon);
markers.push(marker);
allmarkers.push(marker);
}
mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
}
mgr.refresh();
}
function createMarker(posn, title, icon) {
var marker = new GMarker(posn, {title: title, icon: icon, draggable:false });
return marker;
}
function reloadMarkers() {
setupOfficeMarkers();
}
您可以在http://www.trendy-places.com/Amsterdam
看到该脚本我无法找出导致错误的原因。
提前感谢您的帮助!
答案 0 :(得分:1)
检查您的places数组中的尾随逗号。 IE可能会期待另一个元素并导致错误。
"places": [
{
"name": "USA",
"posn": [40.72, -73.9826]
},
{
"name": "Europe",
"posn": [52.370, 4.8966]
}**,**