Javascript jQuery geocomplete街道地址不工作

Javascript jQuery geocomplete街道地址不工作,javascript,jquery,html,geolocation,geocomplete,Javascript,Jquery,Html,Geolocation,Geocomplete,我今天一直在拼命尝试从jQuery Geocomplete获取字段结果,以显示街道地址,但该插件似乎没有将其作为数据geo=“”呈现在我的表单字段或任何其他内容上 在我的HTML中,我有一些字段可以选择街道名称和另一个数字,我需要这两个字段的结果才能转到#BillingAddress。我相信一些JavaScript可以完成这项工作,但我不是这方面的专家 <div class="item"> <input id="autocomplete" placeholder="Look u

我今天一直在拼命尝试从jQuery Geocomplete获取字段结果,以显示街道地址,但该插件似乎没有将其作为数据geo=“”呈现在我的表单字段或任何其他内容上

在我的HTML中,我有一些字段可以选择街道名称和另一个数字,我需要这两个字段的结果才能转到#BillingAddress。我相信一些JavaScript可以完成这项工作,但我不是这方面的专家

<div class="item">
<input id="autocomplete" placeholder="Look up your address" type="text"></input>
</div>
<div class="item" style="display: none;">
<input class="cat_textbox" id="houseNo" data-geo="street_number" type="text" placeholder="House Number" maxlength="50"/>
</div>
<div class="item" style="display: none;">
<input class="cat_textbox" id="street" data-geo="route" type="text" placeholder="street" maxlength="50"/>
</div>
<div class="item">
<input class="cat_textbox" id="BillingAddress" data-geo="street_address" type="text" placeholder="Billing Address" maxlength="50" name="BillingAddress"/>
</div>
非常感谢你的帮助,我认为这也是对其他人的一个很好的质疑

fillDetails:函数(结果){ “结果”对象在“地址组件”中没有“街道地址”,它被设置为结果的一个单独属性-“名称”。 如果您只是键入搜索词并提交,则返回“名称”。如果您再次单击“查找”,则不会返回“名称”

我做了一个快速“修复”来替换“街道地址”,在第338行我添加了以下内容:

    street_addr: result.formatted_address.split(',')[0],
所以第335-339行看起来像这样:

  // Add infos about the address and geometry.
  $.extend(data, {
    formatted_address: result.formatted_address,
    street_addr: result.formatted_address.split(',')[0],
    location_type: geometry.location_type || "PLACES",
并在第65行添加了“街道地址”:

"formatted_address street_addr location_type bounds").split(" ");

您可能已经知道,修改插件不是一件好事。有一种更简单的方法可以连接results对象的元素。只需绑定到结果

$('#geocomplete').geocomplete({
  details: '#geo_details',
  detailsAttribute: 'data-geo',
  types: ['geocode', 'establishment']
}).bind("geocode:result", function(e, r) {
  return $('[data-geo=street_address]').val(r['address_components'][0]['short_name'] + ' ' + r['address_components'][1]['short_name']);
});

这也是一个很好的方式,我必须说,但我确实改变了插件,以避免你正在做的事情,每次有人得到插件,他们将不得不添加更多的行绑定功能正确,但我可以说,这是所有的偏好,你选择使用它的方式,你打算它,只要它工作!我没有测试你的,但我会保留它的记录到tr在另一个项目上,我已经搜索了几个小时如何解决这个可怕的问题,哈哈。我最终使用了你的解决方案,我可以毫无疑问地说它工作完美无瑕。先生,你应该得到一块饼干。但是我不能给你一块饼干,所以我会简单地投票给你的答案。
$('#geocomplete').geocomplete({
  details: '#geo_details',
  detailsAttribute: 'data-geo',
  types: ['geocode', 'establishment']
}).bind("geocode:result", function(e, r) {
  return $('[data-geo=street_address]').val(r['address_components'][0]['short_name'] + ' ' + r['address_components'][1]['short_name']);
});