2013-11-20 225 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