谷歌地图API - 这条线的含义/功能是什么

Google Maps API - what is the meaning/function of this line?

本文关键字:功能 是什么 API 谷歌地图      更新时间:2023-09-26

我正在向我的谷歌地图添加一个搜索框。从文档 (https://developers.google.com/maps/documentation/javascript/examples/places-searchbox):

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

我试图确切地了解这在低水平上是如何工作的。最后一行有什么作用?如果它像注释所说的那样将搜索框链接到 UI 元素,它是如何做到这一点的?

如 https://developers.google.com/maps/documentation/javascript/controls#CustomExample 所述

// Add the control to the map at a designated control position
// by pushing it on the position's array. This code will
// implicitly add the control to the DOM, through the Map
// object. You should not attach the control manually.
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);