2016-04-22 80 views
0

我正在使用Google Map JavaScript Api。 我想将自动填充搜索结果限制在特定城市的地区和地点。Google Places Autocomplete Web Api,获取特定城市的区域

我试图找到谷歌以及在Stackoverflow上,但无法得到答案。

我该如何做到这一点?

的链接,获取我使用的API是如下

<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initAutocomplete" 
async defer></script> 

任何帮助将是宝贵的!

+0

你见过这个帖子:http://stackoverflow.com/questions/10637183/how-can-i-restrict-the-google-maps-places-librarys-autocomplete-to-suggestions和http://stackoverflow.com/questions/8282026/how-to-limit-google-autocomplete-results-to-city-and-country-only? –

+0

不,我在提问时找不到那个问题。 你能帮我吗,我怎么能找到一个地方西北和东南latlong? –

回答

0
function initAutocomplete() { 
    autocomplete = new google.maps.places.Autocomplete(
      (document.getElementById('cities')),{types: ['establishment']}); 
    autocomplete.addListener('place_changed', function(){}); 
} 

你可以改变它的类型

该类型的预测将被返回。支持四种类型:企业“建立”,地址“地理编码”,行政区域的“(区域)”和地区的“(城市)”。如果没有指定,则返回所有类型。

https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest

+0

这只允许将搜索限制在国家而不是所选城市的特定区域。 –

相关问题