我有一些标准的谷歌地方自动完成代码可以正常工作。当用户从列表中选择地址时,我想修改结果。
例如,其中一个结果是
'45 Alexandra Road Holiday Flats, Alexandra Road, 绍斯波特, 英国'
当用户从列表中选择它时,我希望以下值出现在文本框中
'45 Alexandra Road Holiday Flats, Alexandra Road, Southport, PR4 5JD'
即,我希望插入邮政/邮政编码并删除英国。
我可以在 place_changed 事件中执行此操作,邮政/邮政编码可用,我可以进行一些字符串操作并获得我想要的结果。
但是,当我将它分配给“place_changed”函数末尾的 txtBox 时,某些东西会在没有邮政/邮政编码的情况下将其更改回原始选定值。这是最近发生的变化,因为我的代码过去可以工作。将值分配/绑定到 txtBox 发生在 place_changed 事件之后,现在看起来。
var autoCompleteObject = new google.maps.places.Autocomplete(txtBox[0], GooglePlacesOptions);
// Autocomplete Listener
google.maps.event.addListener(autoCompleteObject, 'place_changed', function () {
var place = autoCompleteObject.getPlace();
txtBox.val('45 Alexandra Road Holiday Flats, Alexandra Road, Southport, PR4 5JD');
});
任何关于如何实现这一目标的想法将不胜感激。
非常感谢,
标记