我的代码运行正常。 但突然间它停止工作并发出错误 -
Uncaught RangeError: Maximum call stack size exceeded
如何调试此错误? 我没有改变任何东西,但它仍然给出了这个错误。
下面提到了代码 -
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
var marker;
<!--Intializing the script for displaying map-->
function initialize()
{
<!--url_arrays will store the arrays passed as url parameter,url is the encoded url with parameter passed to the iframe without '?' and '&' character which is used to separate the parameters from the url-->
var url_arrays = [],url_param;
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
<!--if the subtring contains any '=' character it will remove them & will store them in url_arrays array-->
for (var i = 0; i < url.length; i++)
{
url_param = url[i].split('=');
url_arrays.push(url_param[0]);
url_arrays[url_param[0]] = url_param[1];
}
<!--As the url is in encoded format, it has to be decoded-->
var lat_tmp = decodeURIComponent(url_arrays[0]).split(','||' ');
var long_tmp = decodeURIComponent(url_arrays[1]).split(','||' ');
<!-- these arrays will contain the lattitude & longitude values-->
var lattitude=[];
var longitude=[];
<!--The negetive or posive value has to be extracted from the string-->
for (var i = 0; i < lat_tmp.length; i++)
{
lattitude.push(parseFloat(lat_tmp[i].match(/-?\d*\.{0,1}\d+/), 10));
longitude.push(parseFloat(long_tmp[i].match(/-?\d*\.{0,1}\d+/), 10));
}
<!--Finding the maximum, minimum value of lattitude & longitude array. It will be useful to set auto zoom of the map -->
var max_lattitude=lattitude[0],min_lattitude=lattitude[0];
var max_longitude=longitude[0],min_longitude=longitude[0];
for(var i=0;i<lattitude.length;i++)
{
if(max_lattitude<lattitude[i])
max_lattitude=lattitude[i];
if(min_lattitude>lattitude[i])
min_lattitude=lattitude[i];
if(max_longitude<longitude[i])
max_longitude=longitude[i];
if(min_longitude>longitude[i])
min_longitude=longitude[i];
}
<!--Finding the center of the co-ordinates-->
var lattitude_center=(max_lattitude+min_lattitude)/2;
var longitude_center=(max_longitude+min_longitude)/2;
document.getElementById("lattitude").innerHTML = max_lattitude+" : "+min_lattitude;
document.getElementById("longitude").innerHTML = max_longitude+" : "+min_longitude;
var mapObject = {
center:new google.maps.LatLng(lattitude_center,longitude_center),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapObject);
for(var i=0;i<lattitude.length;i++)
{
var myCenter=new google.maps.LatLng(lattitude[i],longitude[i]);
var marker=new google.maps.Marker({
position:myCenter,
animation:google.maps.Animation.BOUNCE
});
<!--Auto zooming the map based on the minimum & maximun lattitude, longitude-->
map.fitBounds(new google.maps.LatLngBounds(
//bottom left
new google.maps.LatLng(min_lattitude, min_longitude),
//top right
new google.maps.LatLng(max_lattitude, max_longitude)
));
marker.setMap(map);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
Lattitude: <div id="lattitude"/></div>
Longitude: <div id="longitude"/></div>
</body>
</html>
我尝试了不同的网络浏览器。但问题仍然存在。
答案 0 :(得分:0)
map.fitBounds()
函数抛出此错误。