Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个JS函数打印的Javascript/Google地理编码地址_Javascript_Google Maps_Geocode - Fatal编程技术网

从另一个JS函数打印的Javascript/Google地理编码地址

从另一个JS函数打印的Javascript/Google地理编码地址,javascript,google-maps,geocode,Javascript,Google Maps,Geocode,我正在使用Javascript对城市/国家输入值进行地理编码,这是另一个JS函数的结果。将结果输入到值的函数称为sata(),Google Geocode函数称为UpdateMap(),它在两个不同的输入中打印出纬度和经度。我确实需要一些帮助来让它工作。我试着使用一些事件监听器,但到目前为止还没有成功,除非我做得不对 JS将两个输入合并到一个城市,输入值id为“refcity”的国家 JS将城市、国家/地区输入的“jobadder”转换为纬度/经度。我试着在输入中使用onchange,但不起作用

我正在使用Javascript对城市/国家输入值进行地理编码,这是另一个JS函数的结果。将结果输入到值的函数称为sata(),Google Geocode函数称为UpdateMap(),它在两个不同的输入中打印出纬度和经度。我确实需要一些帮助来让它工作。我试着使用一些事件监听器,但到目前为止还没有成功,除非我做得不对

JS将两个输入合并到一个城市,输入值id为“refcity”的国家

JS将城市、国家/地区输入的“jobadder”转换为纬度/经度。我试着在输入中使用onchange,但不起作用

 // Update the Google map for the user's inputted address
function UpdateMap()
{ 
   var geocoder = new google.maps.Geocoder();    // instantiate a geocoder object
    // Get the user's inputted address
    var address = document.getElementById("jobadder").value;

    // Make asynchronous call to Google geocoding API
    geocoder.geocode( {'jobadder': address}, function(results, status) {
        var addr_type = results[0].types[0];    // type of address inputted that was geocoded
        if ( status == google.maps.GeocoderStatus.OK )
        { 
             var location = results[0].geometry.location,
        lat      = location.lat(),
        lng      = location.lng();

         document.getElementById("test1").value = lat;
         document.getElementById("test2").value = lng; 
        } 
        else    
        {   
            alert("Geocode was not successful for the following reason: " + status);     
        } 
    });
}

是否可以向UpdateMap函数中添加一个参数,并在希望更新时将其传递为“allja”,而不是监视“jobadder”?请尝试使用常数作为地址的UpdateMap(),看看它是否有效。然后,我会将UpdateMap()放在sata()中,作为测试它的最后一行。首先确保每个函数都使用常量而不是变量。
 // Update the Google map for the user's inputted address
function UpdateMap()
{ 
   var geocoder = new google.maps.Geocoder();    // instantiate a geocoder object
    // Get the user's inputted address
    var address = document.getElementById("jobadder").value;

    // Make asynchronous call to Google geocoding API
    geocoder.geocode( {'jobadder': address}, function(results, status) {
        var addr_type = results[0].types[0];    // type of address inputted that was geocoded
        if ( status == google.maps.GeocoderStatus.OK )
        { 
             var location = results[0].geometry.location,
        lat      = location.lat(),
        lng      = location.lng();

         document.getElementById("test1").value = lat;
         document.getElementById("test2").value = lng; 
        } 
        else    
        {   
            alert("Geocode was not successful for the following reason: " + status);     
        } 
    });
}