Javascript 如何更改谷歌地图搜索结果的位置?
这是我用来在谷歌地图中显示搜索框的代码Javascript 如何更改谷歌地图搜索结果的位置?,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,这是我用来在谷歌地图中显示搜索框的代码 function setSearchbox(map) { // Create the search box and link it to the UI element. var input = document.getElementById('searchLocation'); var searchBox = new google.maps.places.SearchBox(input); // Bias the Searc
function setSearchbox(map) {
// Create the search box and link it to the UI element.
var input = document.getElementById('searchLocation');
var searchBox = new google.maps.places.SearchBox(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function () {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// [START region_getplaces]
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function () {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
// Clear out the old markers.
markers.forEach(function (marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function (place) {
var icon = {
url: place.icon,
size: new google.maps.Size(40, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
}));
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}
输出是,
是否可以将搜索结果框移动到搜索框的正上方(下拉而不是下拉)
我浏览了很多参考网站,但运气不佳。你想让它“下拉”而不是“下拉”吗?是的,我想让它成为“下拉”。@geocodezip有一个CSS解决方案,但有没有合适的解决方案可以实现这一点?如果你有适合自己的解决方案,不确定“合适”的解决方案是什么意思(并且不依赖于未记录的行为),使用它。我的意思是,如果API中有一个选项,那么它将是一个合适的选项,如果我编写css,那么当API中有新的更新可用时,会有一些更改来删除。我将添加一些解决方法作为答案。非常感谢。