添加搜索栏到谷歌地图地点



我想在我的谷歌地图上添加一个搜索栏。我需要搜索栏来查找酒店。有没有办法做到这一点?当前 JS 如下。

function initMap() {
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
center: {
lat: 46.619261,
lng: -33.134766
}
});
var labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var locations = [
{ lat: 40.785091, lng: -73.968285 },
{ lat: 41.084045, lng: -73.874245 },
{ lat: 40.754932, lng: -73.984016 }
];
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
var markerCluster = new MarkerClusterer(map, markers, { imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
}

目前,无法筛选出地点 API 自动完成服务返回的预测,这些预测仅针对酒店或住宿。

但是,我们在Google问题跟踪器中确实有一个现有的功能请求。为了表达您的兴趣并订阅其最新更新,我建议您为以下条目加注星标:https://issuetracker.google.com/35820774

同时,你可能想要查看此示例,该示例使用自动完成服务,该服务经过筛选,仅返回与localityadministrative_area_level_3匹配的结果,方法是使用types: ['(cities)']

选择城市后,它将使用筛选为types: ['lodging']的附近搜索服务在地图的视口内查找所选城市中的所有附近酒店。

var search = {
bounds: map.getBounds(),
types: ['lodging']
};

最新更新