Google maps 谷歌放置自动完成-类型:地理编码,地址,机构-工作不正常

Google maps 谷歌放置自动完成-类型:地理编码,地址,机构-工作不正常,google-maps,google-maps-api-3,google-places-api,googleplacesautocomplete,Google Maps,Google Maps Api 3,Google Places Api,Googleplacesautocomplete,我正试图在谷歌places autocomplete中设置类型,这让我抓狂 我希望我的用户能够通过键入他们正在寻找的地址或机构来过滤那里的搜索,但由于某些原因,它无法正常工作 我正在使用的代码: <script defer src="https://maps.googleapis.com/maps/api/js?libraries=places&key=[my_api_key]"></script> <script> var

我正试图在谷歌places autocomplete中设置类型,这让我抓狂

我希望我的用户能够通过键入他们正在寻找的地址或机构来过滤那里的搜索,但由于某些原因,它无法正常工作

我正在使用的代码:

<script defer src="https://maps.googleapis.com/maps/api/js?libraries=places&key=[my_api_key]"></script>
<script>
    var searchInputStart = 'start_address';
    start_address = new google.maps.places.Autocomplete((document.getElementById(searchInputStart)), {
        types: ['geocode'],
        types: ['address'],
        types: ['establishment']
    });
    google.maps.event.addListener(start_address, 'place_changed', function () {
        var place_start = start_address.getPlace();
        document.getElementById('loc_lat_start').value = place_start.geometry.location.lat();
        document.getElementById('loc_long_start').value = place_start.geometry.location.lng();
        //get_directions to address
        set_route();
    });
</script>

var searchInputStart='start_address';
start\u address=new google.maps.places.Autocomplete((document.getElementById(searchInputStart)){
类型:['geocode'],
类型:[“地址”],
类型:[“机构”]
});
google.maps.event.addListener(开始地址,'place\u changed',函数(){
var place_start=start_address.getPlace();
document.getElementById('loc_lat_start')。value=place_start.geometry.location.lat();
document.getElementById('loc_long_start')。value=place_start.geometry.location.lng();
//获取地址的方向
set_route();
});
如果我取出-->类型:[address]-->它将显示正确的机构,但不显示地址

如果我取出-->类型:[机构设置]-->它会显示正确的地址,但不会显示机构设置

我的用户如何从键入地址或机构中正确筛选位置

有人能帮我吗?我做错了什么


谢谢。

根据谷歌地图API文档,您只能设置一种类型的就地自动完成选项

类型
数组
:要返回的预测类型。有关受支持类型的列表,请参阅《开发人员指南》。如果未指定任何内容,则返回所有类型通常只允许单一类型。例外情况是,您可以安全地混合使用“地理编码”和“建立”类型,但请注意,这与不指定任何类型具有相同的效果

资料来源:

这意味着你可以使用

start_address = new google.maps.places.Autocomplete(
    document.getElementById(searchInputStart), 
    {
        types: ['address']
    }
);

但并非所有选项都在同一个选项对象中


我希望我的回答能澄清你的疑问。

你好,xomena。非常感谢你帮助我。你的帮助使我明白了。在我的情况下,最好不要使用任何类型。我只需要从我的用户那里得到地址。
start_address = new google.maps.places.Autocomplete(
    document.getElementById(searchInputStart), 
    {
        types: ['geocode', 'establishment']
    }
);