2016-12-17 101 views
0

Courchevel, Saint-Bon-Tarentaise, France出現在結果中,但是當我想使用此地址時geocode無法識別它。Google api autocomplete無法識別地址

它只承認這一個Courchevel 1650, Saint-Bon-Tarentaise, France

我該如何使原始地址可被識別?

var placeSearch, autocomplete, destination; 
var componentForm = { 
    street_number: 'short_name', 
    route: 'long_name', 
    locality: 'long_name', 
    administrative_area_level_1: 'short_name', 
    country: 'long_name', 
    postal_code: 'short_name' 
}; 

function initAutocomplete() { 
    // Create the autocomplete object, restricting the search to geographical 
    // location types. 
    autocomplete = new google.maps.places.Autocomplete(
     /** @type {!HTMLInputElement} */ 
     (document.getElementById('from')), { 
      types: ['geocode'] 
     } 
    ); 

    // When the user selects an address from the dropdown, populate the address 
    // fields in the form. 
    autocomplete.addListener('place_changed', fillInAddress); 

    destination = new google.maps.places.Autocomplete(
     /** @type {!HTMLInputElement} */ 
     (document.getElementById('to')), { 
      types: ['geocode'] 
     } 
    ); 

    // When the user selects an address from the dropdown, populate the address 
    // fields in the form. 
    destination.addListener('place_changed', fillInAddressDestination); 
} 

// [START region_fillform] 
function fillInAddress() { 
    var place = autocomplete.getPlace(); 

    for (var component in componentForm) { 
     document.getElementById(component).value = ''; 
     document.getElementById(component).disabled = false; 
    } 

    // Get each component of the address from the place details 
    // and fill the corresponding field on the form. 
    for (var i = 0; i < place.address_components.length; i++) { 
     var addressType = place.address_components[i].types[0]; 
     if (componentForm[addressType]) { 
      var val = place.address_components[i][componentForm[addressType]]; 
      document.getElementById(addressType).value = val; 
     } 
    } 
} 
// [END region_fillform] 

回答

0

我一直在試圖重現該問題,在谷歌Autocomplete Address FormPlace Autocomplete測試這兩個地址。谷歌似乎試圖將你的搜索放在某個地方,並將它放在一般的「高雪維爾地區」。

似乎沒有正確的方法來解決這個問題,使用谷歌API,除了使用更精確的地址或谷歌reporting the address issue,並等待他們修復API。 (我認爲他們實際上對這些做出了迅速反應)。

我試圖使用SmartyStreets驗證地址。它符合你的地址,這一點,我不知道這是否是正確的:

enter image description here

我會建議使用地址的API,像SmartyStreets,這並不覈查(即,它會針對地址數據發現一個已知的地址並找出它的位置,而不是僅僅試圖找出輸入的所有搜索字詞;如果地址比地圖更重要,或者如果您正在運輸或類似的東西,那麼它尤其方便。

完全披露:我曾爲SmartyStreets工作。