使用componentRestrictions仅在Google Maps中的一种状态 [英] Use componentRestrictions to just one state in Google Maps
本文介绍了使用componentRestrictions仅在Google Maps中的一种状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Google地方信息自动完成功能中使用componentRestrictions
.我可以按国家/地区来限制,但是当我尝试按行政区域来限制时,整个过程都会崩溃.
I am trying to use componentRestrictions
in Google Places autocomplete. I can restrict by country, but when I try to restrict by administrative area, the whole thing crashes.
var options = {
componentRestrictions: { administrativeArea: 'TX' }
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}
});
推荐答案
恐怕你做不到,因为 查看全文