簡體   English   中英

Google API自動完成功能無法識別地址

[英]Google api autocomplete doesn't recognize address

Courchevel, Saint-Bon-Tarentaise, France出現在搜索結果中,但當我要使用此地址時, geocode無法識別。

它僅能識別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]

我一直在嘗試重現此問題,並在Google 自動填充地址表格地方自動填充上測試了這兩個地址。 似乎Google試圖將您的搜索放在某處,並且只是將其放置在一般的“高雪維爾地區”。

除了使用更精確的地址或向Google 報告地址問題並等待他們修復API外,似乎沒有使用Google API修復此問題的正確方法。 (我認為他們實際上對此反應很快。)

我嘗試使用SmartyStreets驗證地址。 它與您的地址與此相對應,我不確定是否正確:

在此處輸入圖片說明

我建議使用諸如SmartyStreets之類的地址API進行驗證(這意味着,它會根據地址數據進行檢查以找到已知地址並進行精確定位,而不是僅在輸入所有搜索字詞后才對其進行精確定位;如果該地址非常方便,對您來說比地圖更重要,或者您在進行運輸或諸如此類的操作時)。

全面披露:我為SmartyStreets工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM