2016-04-22 107 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

這隻允許將搜索限制在國家而不是所選城市的特定區域。 –

相關問題