当前,我正在使用 regions 进行地点自动完成输入。我以前在 regions 之前使用过 citys ,因为这在输入中输出了城镇。
但是现在我希望能够输入邮政编码或城镇/城市,并且仍然只输出城镇/城市。
基本上,我想使用区域,但将城市的输出输入到输入元素中。
以下示例:
Input: London
Actual Output: London, UK (This is fine)
Desired Output: London, UK
Input: SW1A
Actual Output: London SW1A, UK (This is not fine)
Desired Output: London, UK
Input: NW3 7JR
Actual Output: Hampstead Lane, London NW3 7JR, UK (This is not fine)
Desired Output: London, UK
当前使用的Javascript:
//Function for Places Autocomplete
function activatePlacesSearch(){
var input = document.getElementById('id_local_area');
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'gb'}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
答案 0 :(得分:0)
简而言之,这永远不会发生。
位置自动完成功能将始终将输入回显给用户,因此,如果键入邮政编码的一部分,则至少邮政编码的一部分 将成为预测的一部分。使用types =参数可以限制预测,但是在上面的示例中,这只会导致不返回任何预测。
您可以做一些事情:
structured_formatting.secondary_text
级别,尽管不一定总是您想要的“英国伦敦”级别,但它在“地点自动完成”响应中始终可用,因此甚至不需要为“地点ID”执行“详细信息”请求。