谷歌地图自动完成获取完整地址

时间:2019-01-20 15:06:13

标签: search autocomplete maps

Hi StackOverflow社区。

我正在尝试创建一个输入字段,用户可以在其中输入完整的地址。 Google Maps API会自动完成其余缺少字符的功能。我的问题是当前我只能返回街道名称,但地址缺少街道编号。对于我的项目,我需要带有数字的完整地址。看来我需要我在Google api docomentation上阅读的street_address类型。

https://developers.google.com/places/supported_types

但是我无法将其应用于我的项目。我一直在努力寻找一个解决方案,但是却找不到适合我需求的解决方案。我目前对如何使用这些类型有些困惑,因为我能够使用(Regions)和adress类型。我在做什么错?用Google Maps API实施完整地址搜索的最佳实践是什么?

     <input name="searchQuery" placeholder="Intast adresse" id="autoComplete" style="border-radius: 5px;  width :250px; height:40px; padding-left:10px; max-width:400px; border: 2px solid darkblue" type="text" value="" />
     <input style="color:white; background-color:orange; width:auto; height:40px; border: 2px solid orange; margin-left:20px; border-radius: 5px; " type="submit" value="Udlej - Gratis" />

                        <script>
                            function activatePlacesSearch() {
                                var optionsT = {
                                    types: ['street_address'],
                                    componentRestrictions: { country: "dk" }
                                };

                                var input = document.getElementById('autoComplete');
                                var autocomplete = new google.maps.places.Autocomplete(input, optionsT);
                            }
                        </script>

                        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=HiddenKey&libraries=places&street_address&callback=activatePlacesSearch"></script>

0 个答案:

没有答案