当前位置: 代码迷 >> JavaScript >> Javascript:未捕获的RangeError:超出最大调用堆栈大小
  详细解决方案

Javascript:未捕获的RangeError:超出最大调用堆栈大小

热度:75   发布时间:2023-06-05 11:56:03.0

我的代码运行正常。 但是突然,它停止工作并给出了此错误-

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>

我尝试使用其他网络浏览器。 但是问题仍然存在。

map.fitBounds()函数map.fitBounds()此错误。

原因

  • 它未接收到纬度/经度,或两者均未接收。
  • 接收到的纬度/经度值格式不正确(NaN)。
  相关解决方案