javascript - 地址 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 来检索给定地址所在的学区?
解决方案
推荐阅读
- macos - 在 macOS 的 WebStorm 中查看分支模式屏幕的键盘快捷键是什么?
- amp-html - amp-base-carousel loop 不会循环通过 carousel
- php - 有没有办法在 CSS 样式中使用 PHP var 作为高度和宽度?
- sidebar - 我想在烧瓶管理中将菜单栏更改为侧边栏
- c# - 使用.net MVC中的路由将Url的第一个字母大写(Url Routing to UpperCase)
- python-3.x - Celery Canvas:如何将任务的结果列表的元素分发到链并在之后链其他
- wso2 - WSO2 APIM 3.1.0 服务器无法启动并出现 Qpid 错误
- flutter - 在 Flutter 中将图像添加到 ListTile - 具体问题
- docker - 从在线教程创建我的第一个 Docker 映像时,我收到此错误
- r - 读取大型 csv 文件并加入 r