单击无法正常工作

时间:2016-11-07 06:05:48

标签: javascript jquery google-maps latitude-longitude

我想在单击时调用此功能,但单击时无效。

<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 个答案:

答案 0 :(得分:0)

它实际上是在调用,但您的代码中的实际问题是Google代码,请确保您的代码内部的代码首先处于工作状态。

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" />