我创建了一个Google地图应用程序,用于显示公司的投资组合。奇怪的是,我的标记只是没有在ie8中显示。有没有人有解决方案?这是javascript代码。
var map;
function initialize() {
var myOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
[arrays with data]
var infoWindow = new google.maps.InfoWindow;
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
// Set the center of the map
var pos = new google.maps.LatLng(50.941641437268906, 9.088932512500037);
map.setCenter(pos);
function infoCallback(infowindow, marker) {
return function() {
infowindow.open(map, marker);
};
function setMarkers(map, all) {
for (var i in all) {
var adres = all[i][0];
var name = all[i][1];
var property = all[i][2];
var office = all[i][3];
var warehouse = all[i][4];
var other = all[i][5];
var total = all[i][6];
var parkingspaces = all[i][7];
var yearOfConstruction = all[i][8];
var lat = all[i][9];
var lng = all[i][10];
var latlngset;
latlngset = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
map: map, title: adres, position: latlngset, icon: image
});
var image = 'images/pandklein.png';
var content = '<div id=content>' +'<img class="thumpnail" src="thumpnail/' + name + '.png" alt ="' + name + '">' + '<div class="map-content"><h3 class="title">' + adres + '</h3>' +
'Lettable floor area (m²):' + "<p class='tekst'>" + total + "</p>" + '<br />' + 'Property:' + ' ' + "<p class='tekst'>" + property + "</p>" +
'<br />' + 'Year of construction:' + ' ' + "<p class='tekst'>" + yearOfConstruction + "</p>" + '</div>';
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(content);
google.maps.event.addListener(
marker,
'click',
infoCallback(infowindow, marker)
);
}
}
// Set all markers in the all variable
setMarkers(map, all);
};
// Initializes the Google Map
google.maps.event.addDomListener(window, 'load', initialize);
答案 0 :(得分:0)
我尝试重现您的问题并编写以下html,但标记显示在IE8中。因此,我假设您在此处发布的代码遗漏了您的错误(可能)错误。
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript" charset="UTF-8"></script>
</head>
<body>
<div id="map_canvas" style="width:400px;height:400px;">
</div>
<script type="text/javascript">
var map;
function initialize() {
var myOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow;
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
// Set the center of the map
var pos = new google.maps.LatLng(50.941641437268906, 9.088932512500037);
map.setCenter(pos);
function infoCallback(infowindow, marker) {
return function() {
infowindow.open(map, marker);
};
}
function setMarkers(map, all) {
for (var i in all) {
var adres = all[i][0];
var name = all[i][1];
var property = all[i][2];
var office = all[i][3];
var warehouse = all[i][4];
var other = all[i][5];
var total = all[i][6];
var parkingspaces = all[i][7];
var yearOfConstruction = all[i][8];
var lat = all[i][9];
var lng = all[i][10];
var latlngset;
latlngset = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({map: map, title: adres, position: latlngset}); //icon: image});
//var image = 'images/pandklein.png'; // why declared here?
var content = '<div id=content>' +'<img class="thumpnail" src="thumpnail/' + name + '.png" alt ="' + name + '">' + '<div class="map-content"><h3 class="title">' + adres + '</h3>' +
'Lettable floor area (m²):' + "<p class='tekst'>" + total + "</p>" + '<br />' + 'Property:' + ' ' + "<p class='tekst'>" + property + "</p>" +
'<br />' + 'Year of construction:' + ' ' + "<p class='tekst'>" + yearOfConstruction + "</p>" + '</div>';
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(content);
google.maps.event.addListener(marker, 'click', infoCallback(infowindow, marker));
}
}
var all = [["", "", "", "", "", "", "", "", "", 51, 9]];
// Set all markers in the all variable
setMarkers(map, all);
}
// Initializes the Google Map
google.maps.event.addDomListener(window, 'load', initialize());
</script>
</body>
</html>