我使用AutoComplete
的Google地图。
当我从列表中选择位置时,我从autoComplete.getPlace()
函数获得了位置,并且有一个名为adr_address
的变量,它的值看起来像这样:
"<span class="street-address">xxx</span>, <span class="locality">xxx</span>, <span class="country-name">xxx</span>"
我的问题是,当我自己写地址而不从列表中选择地址时,我在adr_address
函数中没有getPlace
变量,并且如果{状态确定,我想获得与Geocoder
中相同的结果。
我该怎么做?
答案 0 :(得分:0)
我找到了一种通过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
}
});