2016-12-17 48 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工作。