2016-12-17 5 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

Я пытался воспроизвести проблему, проверяя эти два адреса на Google Autocomplete Address Form и Place Autocomplete. Похоже, Google пытается разместить ваш поиск где-то и просто помещает его в общий «район Куршевеля».

Возможно, нет правильного способа исправить это с помощью API Google, за исключением использования более точных адресов или reporting the address issue для Google и ожидания их исправления API. (Я думаю, что они на самом деле быстро реагируют на них.)

Я попытался подтвердить адрес, используя SmartyStreets. Это соответствует вашему адресу к этому, и я не уверен, если это правильно:

enter image description here

Я хотел бы предложить использовать адрес API, как SmartyStreets, что делает проверки (значение, он проверяет против адресных данных, чтобы найти известный адрес и точно определить его, а не просто пытаться точно определить все условия поиска, поскольку они введены, особенно удобно, если адрес более важен для вас, чем карта, или если вы делаете доставку или что-то в этом роде).

Полное раскрытие информации: Я работал на SmartyStreets.

Смежные вопросы