我有一個表單,它使用Google地方庫(在JSFiddle中爲demo,如果我將gmaps.js添加爲腳本中引用它不會工作,但如果我添加它作爲HTML部分完全相同的腳本能正常工作的腳本元素),看起來像這樣:使用Google Maps +地方庫獲得「太多遞歸」錯誤
<form action="#" method="post">
<table class='Information table table-bordered'>
<caption>Information</caption>
<colgroup>
<col width='100' />
<col/>
</colgroup>
<tbody>
<tr>
<th>Location</th>
<td>
<div class="input-append">
<input type="text" name="Lat" value="37.771424" />
<span class="add-on">lat.</span>
</div>
<div class="input-append">
<input type="text" name="Lng" value="-122.41332799999998" />
<span class="add-on">lng.</span>
</div>
</td>
</tr>
<tr>
<th>Map</th>
<td>
<div id="panel">
<form class="form-search">
<input type="text" class="input-medium search-query" autocomplete="off" id="target" placeholder="Search Box"/>
</form>
</div>
<div id="ScavengerMap"></div>
</td>
</tr>
</tbody>
</table>
</form>
用下面的JavaScript:
var input = document.getElementById('target'),
searchBox = new google.maps.places.SearchBox(input),
map = new GMaps({
div: '#ScavengerMap',
lat: 37.771424,
lng: -122.41332799999998
});
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces(),
location;
if (places.length > 0) {
location = places[0].geometry.location;
map.removeMarkers();
map.setCenter(location.jb, location.kb);
map.addMarker({
lat: location.jb,
lng: location.kb,
title: "Slim\'s",
draggable: true,
dragend: function (e) {
var point = e.latLng;
$('input[name=Lat]').val(point.lat());
$('input[name=Lng]').val(point.lng());
}
});
$('input[name=Lat]').val(location.jb);
$('input[name=Lng]').val(location.kb);
}
});
map.addMarker({
lat: 37.771424,
lng: -122.41332799999998,
title: "Slim\'s",
draggable: true,
dragend: function (e) {
var point = e.latLng;
$('input[name=Lat]').val(point.lat());
$('input[name=Lng]').val(point.lng());
}
});
當您在搜索框中輸入內容(例如「Slim's」)時,您會看到一組來自Google Places庫的建議。如果你選擇一個,它應該在那個位置畫一個標誌,而是我得到這兩個錯誤:
too much recursion
[Break On This Error]
...))};sa(fg[E],function(a){var b=this.ua,c=Sf(a);b[c]&&(delete b[c],O[m](this,vf,a...
{main,places}.js (line 26)
too much recursion
[Break On This Error]
....route=function(a,b){Mf("directions",function(c){c.pi(a,b,!0)})};function P(a,b,...
說我有一個很難制定出的東西是爲什麼。本演示中的代碼是我的項目中的代碼的子集,但都提出了相同的問題。我找不到有關Google地圖庫或Google Maps API停用的任何信息,而且更早的兩週前(我寫這篇文章的時候),這個完全相同的代碼仍然有效。關於如何至少可以隔離問題的任何想法?
你也可以使用'map.setCenter(location.lb,location.mb);':) –
爲什麼你會推薦使用一個對象的非文檔屬性(這就是.lb和.mb)?當Google推出新版本(或可能)時,它會再次突破。 – geocodezip