Google Maps API - 这条线的含义/功能是什么?

时间:2016-03-04 16:32:49

标签: javascript google-maps

我在我的Google地图中添加了一个搜索框。从文档(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元素,它是如何做到的?

1 个答案:

答案 0 :(得分:0)

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);