2016-11-07 52 views
-2

我想在单击时调用此功能,但它不能用于单击。单击不起作用

<input id="search" type="button" onClick="codeAddress();" value="Search Location" /> 

function codeAddress() { 
    geocoder = new google.maps.Geocoder(); 
    var address = document.getElementById("box").value; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      a = results[0].geometry.location.lat(); 
      b = results[0].geometry.location.lng(); 
      myLatlng = new google.maps.LatLng(a, b); 
     } 
     else { 
      alert("Geocode was not successful for the following reason: " + status); 
     } 
    }); 
    initialize(); 
} 
+1

“它不工作”,这是一个错误,我总是在这个网站 – madalinivascu

+0

你是否包括谷歌地图JavaScript API V3获得最详细的说明?请提供证明问题的[mcve]。 – geocodezip

回答

0

它实际上是调用,但在你的代码中的实际问题是谷歌代码,请确保您的第一个代码中的功能处于工作状态。

function codeAddress() { 
 
    alert('hello its calling, the problem is in your google code, that is the actual problem!'); 
 
     }
<input id="search" type="button" onClick="codeAddress();" value="Search Location" />

+0

是的,codeAddress()正在工作,错误发生在我在codeAddress()中调用的函数“initialize()”中。我解决了它......谢谢Jagar7521 – mansoor

+0

是的,这就是我在回答中所说的你读过的那篇文章吗? – Jigar7521

+0

是的,我读过。 – mansoor