首页 > 解决方案 > 地址 api-> 学区查询

问题描述

我正在使用 google map api 进行项目,我可以从地址中检索县、市、邮政编码、国家、经度和纬度,但我也想获得学区,但我不知道怎么做检索这个。下面是我的代码:

<script>
    let placeSearch;
    let autocomplete;
    const componentForm = {
        country: "long_name",
        postal_code: "short
        locality: "long_name", //city
        administrative_area_level_2: "long_name", //county
        };

        google.maps.event.addDomListener(window, 'load', initialize);
        function initAutocomplete(){
            autocomplete = new google.maps.places.Autocomplete(
            document.getElementById('autocomplete'), {types: ['geocode']});
            autocomplete.addListener('place_changed', getAddressDetails);
        }
        function getAddressDetails(){
            [var place = autocomplete.getPlace();
            document.getElementById("latitude").value = place.geometry.location.lat();
            document.getElementById("longitude").value = place.geometry.location.lng();
            // --------- show lat and long ---------------
            $("#lat_area").removeClass("d-none");
            $("#long_area").removeClass("d-none");
            fillInAddress();
        } 
        function fillInAddress() {
            // Get the place details from the autocomplete object.
            const place = autocomplete.getPlace();
            console.log(place);

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

            // Get each component of the address from the place details,
            // and then fill-in the corresponding field on the form.
            for (const component of place.address_components) {
                const addressType = component.types[0];
                if (componentForm[addressType]) {
                    const val = component[componentForm[addressType]];
                    document.getElementById(addressType).value = val;
                 }

             }
    }


</script>

有什么方法可以添加 componentForm 来检索给定地址所在的学区?

标签: javascriptlaravel

解决方案


推荐阅读