0

我正在使用谷歌地图来在地图上显示标记。我从谷歌地图的实用程序库版本 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现场查看脚本

我无法找出导致错误的原因。

提前谢谢你的帮助!

4

1 回答 1

1

检查您的位置数组中的尾随逗号。IE 可能期待另一个元素并导致错误。

"places": [
  {
    "name": "USA",
    "posn": [40.72, -73.9826]
  },
 {
    "name": "Europe",
    "posn": [52.370, 4.8966]
  }**,**
于 2012-04-09T13:47:43.073 回答