【问题标题】:Get address from geocoder like autocomplete google maps从地理编码器获取地址,如自动完成谷歌地图
【发布时间】:2019-04-07 23:54:34
【问题描述】:

我使用AutoComplete 的谷歌地图。

当我从列表中选择位置时,我从 autoComplete.getPlace() 函数中获取位置,并且有一个名为 adr_address 的变量,它的值如下所示:

"<span class="street-address">xxx</span>, <span class="locality">xxx</span>, <span class="country-name">xxx</span>"

我的问题是当我自己写地址而不是从列表中选择时,我在getPlace 函数中没有adr_address 变量,我用Geocoder 检查地址,如果状态OK 我想得到与adr_address 中的结果相同。

我该怎么做?

【问题讨论】:

    标签: angular typescript google-maps autocomplete angular-cli


    【解决方案1】:

    我找到了一种通过 place_id 和 PlacesService 从 Geocoder 获取 adr_address 的方法。

    new google.maps.Geocoder().geocode({"address":text }, function(results, status){
                            if (status == google.maps.GeocoderStatus.OK) {
                                var service = new google.maps.places.PlacesService(document.createElement('div'));
                                service.getDetails({
                                    placeId: results[0].place_id
                                }, function(place, status) {
                                    if (status === google.maps.places.PlacesServiceStatus.OK) {
                                        doSomething(place.adr_address);
                                    }
                                });
                            }
                            else {
                                //geocode fail
                            }
                        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-03
      • 2013-03-23
      • 2017-09-16
      • 2013-12-20
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      相关资源
      最近更新 更多