Google Map API v3 – 超出了最大调用堆栈大小
我在过去5或6周内一直在开发JS widget
。 通过简单地将href添加到远程.js文件以及具有给定ID的DIV容器来包含窗口小部件的内容,可以将其添加到任何站点。
该小部件广泛使用Google Map API,我将其引用如下:
https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,places&callback=initializeGoogleMaps
当小部件被加载时,它将要求用户检查其位置的许可,然后在其他操作中执行对该位置的简单地理编码,以便可以在地图上绘制标记。
一切都很完美,我必须在开发过程中测试超过2,000个搜索。
我昨天部署了小部件并成功将其嵌入到主机网站中 – 一切都像以往一样完美。 然而,今天早上,我的小部件随着Chrome的控制台报告而崩溃:
Uncaught RangeError: Maximum call stack size exceeded{main,geometry,places}.js:27 (anonymous function)VM530:33 cVM530:33 TT.(anonymous function).fitBounds{main,geometry,places}.js:48 (anonymous function){main,geometry,places}.js:26 Uf{main,geometry,places}.js:48 O.fitBoundsWRAPPostcodeLocator.js:1541 setupPageWRAPPostcodeLocator.js:964 jQuery.ajax.successjquery.js?time=95944:3 jjquery.js?time=95944:3 k.fireWithjquery.js?time=95944:12 xjquery.js?time=95944:12 b.onload.b.onreadystatechange
由于小部件最后一次工作,我的代码或主机没有任何更改,所以我怀疑Google API有问题。
可以在以下位置查看嵌入到虚拟主机中的我的窗口小部件的示例:
http://pcl.solsticecloud.co.uk
花了几个小时试图找到底线,我仍然不是更聪明。
任何帮助或建议将非常感激。
先感谢您,
马特
感谢Matt Alexander这正是问题和解决方案,但似乎谷歌更改了位置属性的名称,而不是.k和.D了,现在它的.A和.F !,看看下面的控制台日志:
现在它是’.G’和’.K’。 如上所述 – 最好使用’.lat()’和’.lng()’。
你也可以使用
keys = Object.keys(LatLng); geometry.location[keys[0]]; // Obtain value for latitude
我找到了这个问题的原因并找到了解决办法。
我使用以下代码:
address = document.getElementById("strSearch").value; geocoder.geocode({ 'address': address, componentRestrictions: { country: 'GB' } }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { toggleModal(); deleteMarkers(); deleteBanks(); searchSourceLatLng = new google.maps.LatLng(results[0].geometry.location.k, results[0].geometry.location.B); setSearchPointPostcode(results, buildResults); } else { callback(); } })
导致该问题的特定行是:
searchSourceLatLng = new google.maps.LatLng(results[0].geometry.location.k, results[0].geometry.location.B);
“.B”已经工作了几个星期,但现在它似乎不再是一个有效的财产。 相反,“。D”工作,所以我的代码现在可以工作。
由于属性不再有效,我有一个带有空值的LatLng对象,当我试图查看我的地图边界时,这导致地图崩溃。
我很想知道API的变化方式或原因。
另外,我确定一个愚蠢的问题,但为什么“.k”和“.D”? “.Lng”和“.Lat”有什么问题?
很高兴它已经排序了,只是希望API不会再次改变。
您可以循环遍历location
属性并获取坐标而无需直接访问其属性:
geocoder.geocode({ 'address': value.address }, function (results, status) { if (status === google.maps.GeocoderStatus.OK && results.length > 0) { var coords = []; for (var key in results[0].geometry.location) { coords.push(results[0].geometry.location[key]); } return { 'latitude': coords[0], 'longitude': coords[1] }; } });
尝试这个希望它会帮助你
var map = new google.maps.Map(mappnl.el.dom, { zoom: 8, center: { lat: 52.132633, lng: 5.291265999999999 }, mapTypeId: google.maps.MapTypeId.TERRAIN }); var latlong = []; var geocoder = new google.maps.Geocoder(); if(frmvalue.dir_postalcode_standard){ geocoder.geocode({ 'address': frmvalue.dir_postalcode_standard }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { slat = results[0].geometry.location.lat(); slng = results[0].geometry.location.lng(); latlong['standard'] = { 'lat': slat, 'lng': slng }; var cityCircle = new google.maps.Circle({ strokeColor: '#00FF00', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#00FF00', fillOpacity: 0.15, map: map, center: { lat: slat, lng: slng }, radius: frmvalue.dir_radius_standaard * 1000 }); map.setCenter({ lat: slat, lng: slng }); geocoder.geocode({ 'address': frmvalue.dir_postalcode_extended }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { elat = results[0].geometry.location.lat(); elng = results[0].geometry.location.lng(); latlong['extended'] = { 'lat': elat, 'lng': elng }; var cityCircle = new google.maps.Circle({ strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#FF0000', fillOpacity: 0.15, map: map, center: { lat: elat, lng: elng }, radius: frmvalue.dir_radius_extended * 1000 }); callback(latlong); } else { console.log("Geocode was not successful for the following reason: " + status); } }); } else { console.log("Geocode was not successful for the following reason: " + status); } }); } else { callback(false); }