Javascript 从geocomplete(JQuery)提取位置类型

Javascript 从geocomplete(JQuery)提取位置类型,javascript,jquery,forms,geolocation,geocomplete,Javascript,Jquery,Forms,Geolocation,Geocomplete,我试图使用jquery库自动完成google地址,并写入一些隐藏字段变量,如long、lat、location\u类型。它适用于写出来的lat和lng,但我正在努力获取位置类型。以下是我尝试过的: #theJS $(function(){ $("#id_address").geocomplete() .bind("geocode:result", function(event, result){ $.log(result.formatted_address)

我试图使用jquery库自动完成google地址,并写入一些隐藏字段变量,如long、lat、location\u类型。它适用于写出来的lat和lng,但我正在努力获取位置类型。以下是我尝试过的:

#theJS

$(function(){
    $("#id_address").geocomplete()
      .bind("geocode:result", function(event, result){
        $.log(result.formatted_address);
          $("input#id_lat").val(result.geometry.location.lat());
          $("input#id_lng").val(result.geometry.location.lng());
          $("input#id_location_type").val(result.geometry.location_type());
      })
    });

#the HTML forms

<input id="id_lng" name="lng" type="hidden" />
<input id="id_lat" name="lat" type="hidden" />
<input id="id_location_type" name="location_type" type="text" />
<input type="text" name="address" id="id_address" />
#theJS
$(函数(){
$(“#id_地址”).geoplete()
.bind(“地理代码:结果”,函数(事件,结果){
$.log(结果格式化的\u地址);
$(“input#id_lat”).val(result.geometry.location.lat());
$(“input#id_lng”).val(result.geometry.location.lng());
$(“input#id#u location_type”).val(result.geometry.location_type());
})
});
#HTML表单
为了对结果进行故障排除,我尝试了
$(“input#id_location_type”).val(result.geometry)并且它确实会写入位置类型输入框
[object object]
,但只要我将其扩展到
结果.geometry.location\u type
结果.geometry.location\u type()
我就什么也得不到

任何提示,谢谢。(这里有一个例子来说明我想说什么)

试试看

$("input#id_location_type").val(result.types);
而不是

$("input#id_location_type").val(result.geometry.location_type());

基本上,您必须将地理编码方法与
geocode:result
绑定,然后才能提取
lat
lng

$("#location")
  .geocomplete()
  .bind("geocode:result", function (event, result) {
  $("#latitude").val(result.geometry.location.lat());
  $("#longitude").val(result.geometry.location.lng());
  //console.log(result);
});
你可以进一步阅读