所以我这里有点问题。此脚本在除 IE8 之外的所有浏览器中都能正常工作
route() 函数被调用 - 并被赋予谷歌地图编码的多边形和折线。每次 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;
}
}