Mapbox Autosuggest JS 过滤完整地址

问题描述 投票:0回答:1

使用mapbox js自动填充组件时,我尝试仅检索完整地址,而不在自动建议响应中包含街道/高速公路。

如何初始化自动填充以仅包含完整地址?

    autofillCollection = mapboxsearch.autofill({
        options: { 
            country: 'us',
            language: 'en', 
        }
    });
javascript mapbox autofill
1个回答
0
投票

响应包含在事件的详细信息对象中。 例如,您将在以下位置获得信息:featureCollection.features[0].properties.full_address;

    function initAutocomplete() {
        const autofill = document.querySelector('mapbox-address-autofill');
        //const minimap = document.querySelector('mapbox-address-minimap');
        autofill.accessToken = ACCESS_TOKEN;
        autofill.sessionToken = 'testsession-token'
        //minimap.accessToken = ACCESS_TOKEN;
        autofill.addEventListener('retrieve', (event) => {
            const featureCollection = event.detail;
            if (!featureCollection || !featureCollection.features.length) {
                minimap.feature = null;
                return;
            }
            mapboxfeature = featureCollection.features[0];
            //minimap.feature = feature;
            fillInAddress();
        });
        
    }
function fillInAddress() {
        // Get the place details from the autocomplete object.
        var place = mapboxfeature;
document.getElementById('address_autocomplete').value = place.properties.full_address;
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.