所以我在这里遇到了一些问题。除了IE8之外,此脚本在所有浏览器中都能正常运行
调用route()函数 - 并给出Google地图编码的多边形和折线。每次IE8尝试执行setMap
时脚本都会中断我认为问题与地图超出范围有关?或者是一个尾随的逗号错误?我只花了最后几个小时玩这个,我无法解决它。
任何想法?非常感激。通常不喜欢粘贴整个代码,因为它有点压倒性但在这种情况下需要它。
var markersArray = [];
function initMap(lat,lng) {
if(lat) {
var myLatLng = new google.maps.LatLng(lat, lng);
var zoomi=13;
}else{
var myLatLng = new google.maps.LatLng(54.162434, -2.285156);
var zoomi=5;
}
var myOptions = {
zoom: zoomi,
zoomControl: true,
panControl: false,
streetViewControl: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER
},
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
}
function route(journeyPolyy,journeyLine,startLat,startLng,endLat,endLng) {
reset();
var startLatLng=startLat + ',' + startLng;
var start = new google.maps.LatLng(startLat,startLng);
var end = new google.maps.LatLng(endLat,endLng);
var decodedPath = google.maps.geometry.encoding.decodePath(journeyLine);
var flightPath = new google.maps.Polyline({
path: decodedPath,
strokeColor: 'blue',
strokeOpacity: 0.5,
strokeWeight: 5
});
markersArray.push(flightPath);
flightPath.setMap(map);
var marker = new google.maps.Marker({
position: start
});
markersArray.push(marker);
marker.setMap(map);
var endPpoint = new google.maps.Marker({
position: end
});
markersArray.push(endPpoint);
endPpoint.setMap(map);
poly = journeyPolyy.replace(/\\\\/g,"\\");
var decodedPath = google.maps.geometry.encoding.decodePath(poly);
var decodedLevels = decodeLevels("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
var setRegion = new google.maps.Polygon({
path: decodedPath,
levels: decodedLevels,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor : '#FF0000',
fillOpacity : 0.1,
map: map
});
setRegion.setMap(map);
markersArray.push(setRegion);
var obj= document.getElementById('map');
obj.style.visibility='visible';
HideContent('mainContent');
map.setCenter(start);
map.setZoom(13);
}
function decodeLevels(encodedLevelsString) {
var decodedLevels = [];
for (var i = 0; i < encodedLevelsString.length; ++i) {
var level = encodedLevelsString.charCodeAt(i) - 63;
decodedLevels.push(level);
}
return decodedLevels;
}
function reset() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
答案 0 :(得分:3)
存在命名冲突(map-objects名称与元素的id相同)
您可以为div使用不同的id,为map-variable使用不同的名称,或者在全局范围内声明map-variable:
var map;