2013-11-20 222 views
0

我在主頁上使用Google Maps Geocoding來輸入用戶地址。我還寫了一個jQuery腳本,通過按回車鍵觸發提交按鈕。所以,我得到這個代碼Geocoding谷歌地圖地理編碼OVER_QUERY_LIMIT

function getValue(){ 
    var address = document.getElementById("address").value; 
    geocoder.geocode(
     {'address': address}, 
     function(results, status){ 
      if(status == google.maps.GeocoderStatus.OK) 
      { 
       map.setCenter(results[0].geometry.location); 
       var marker = new google.maps.Marker(
       { 
        map: map, 
        position: results[0].geometry.location 
       }); 
      } 

      else 
      { 
       alert("An unknown error occured. Refresh the page or contact the IT team!" + status); 
      } 
    }); 
} 

而且我得到了這個觸發提交按鈕:

function triggerButton(){ 
    $('#address').keypress(function(e){ 
     if(e.keyCode == 13){ 
      $("#submit").click(); 
     } 
    }); 
} 

它的工作原理幾乎正常,但它有一個錯誤。如果我點擊用鼠標提交,就沒有錯誤。但是,如果我點擊輸入點擊提交,就會出現錯誤:OVER_QUERY_LIMIT。我發現這個錯誤意味着我超過了我的配額。但我不知道這究竟意味着什麼,或者我可以如何解決這個問題。我發現很多線程,但沒有線程與我有同樣的問題。

有人可以給我一個提示嗎?

乾杯

編輯:triggerButton功能接通onkeypress負載在文本框中:

<input type="text" id="address" name="address" onkeypress="triggerButton()" /> 
+0

keyup事件「的triggerButton功能負荷onkeypress事件」是什麼意思? –

+0

哦,對不起。看看我的編輯 – Roman

回答

1

嘗試是:

<input type="text" id="address" name="address"" />

JS:

function triggerButton(e){  
     if(e.keyCode == 13){ 
      $("#submit").click(); 
     }  
} 

$('#address').keypress(triggerButton); 

順便說一句,你可以使用,而不是按鍵

+0

如果我嘗試這樣做,整個'Geocode'不再工作了:/ – Roman

+0

不確定你在做什麼,事件(keypress for #address)沒有解僱或者什麼?你如何調用getValue()? –

+0

哦,我注意到你的編輯。 (e)'丟失了。我現在添加它,它工作正常。謝謝 :) – Roman