经过几个小时的工作,我无法始终如一地提取公寓/房间/子前提。拥有这个细节比能够专门分离它更重要,所以我使用它来解决它。
var componentForm = {
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function fillInAddress(place) {
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
var parts = $("#searchField").val().split(",");
$("#street_number").val(parts[0]);
}
我已经像往常一样从自动完成中提取了信息,尽管跳过了“street_number”和“route”。然后在选择后对自动完成值进行简单拆分并使用第一部分,返回整个街道地址(包括工厂/公寓/房屋和街道名称)。
这项工作给了我结果,可以很好地满足我的需要。祝你好运!