2015-02-17 38 views
4

我有一個網站,我想要確定用戶輸入geocoords並使用該地址來進行會議。谷歌地圖只有自動完成的街道號碼

問題是,谷歌自動完成還顯示「郵政編碼只」或街道沒有streetno。

反正在顯示它們之前過濾自動完成結果嗎?

var input = /** @type {HTMLInputElement} */(
      document.getElementById('pac-input')); 
var defaultBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(52.66805480068766, 13.7713623046875), 
      new google.maps.LatLng(52.32191088594773, 12.98858642578125)); 
var autocomplete_options = { 
     bounds: defaultBounds, 
     componentRestrictions: {country: 'de'}, 
     types: ['geocode'] 
    }; 
    autocomplete = new google.maps.places.Autocomplete(input, autocomplete_options); 
    google.maps.event.addListener(autocomplete, 'place_changed', callServer); 

我的測試網站,看看自動完成可以在這裏找到: http://www.winterreifenwechsel.de/welcome/termine

嘗試像14169(郵編)或Wilskistr(街道沒有housenumber)一些投入。

回答

3

您可以在Autocomplete API的URL請求中使用Place Types參數,該參數只接受具有地理編碼的位置。這將啓用基於具有合適的經緯度而不是區域的位置的自動完成結果。

下面是該API請求:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types;=geocode&language;=fr&key;=API_KEY 

欲瞭解更多詳情,請參閱this谷歌的官方文檔。

編輯

然後我會說使用你的webapp商家信息自動填充地址形式。這裏是link,這將限制用戶使用地址,你可以在你的aps中傳遞地址。

+2

我已經使用類型:['geocode']但仍然只有郵編的autocompletes。 – Umingo 2015-02-17 23:43:30