我正在尝试将InfoWindow放置在使用MarkerClusterer分组的多个标记中,但没有成功。我只能生成带有信息窗口或聚类的地图;无法同时使用两者。在网络上搜索使我更加困惑....
起点是google开发者页面:根据我的需求,我创建了以下代码:
然后我就停在这里了。InfoWindow中显示的代码调用的是除“locations”之外的其他对象。尝试得越多,结果越糟糕...
我想给每个标记添加简单的信息:仅标题和每个标记的唯一网址。
有人可以帮忙吗?
起点是google开发者页面:根据我的需求,我创建了以下代码:
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {lat: -15.7942357, lng: -47.8821945}
});
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
});
});
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
var locations = [
{lat: -19.9286, lng: -43.93888},
{lat: -19.85758, lng: -43.9668},
{lat: -18.24587, lng: -43.59613},
{lat: -20.46427, lng: -45.42629},
{lat: -20.37817, lng: -43.41641},
{lat: -20.09749, lng: -43.48831},
{lat: -21.13594, lng: -44.26132},
]
</script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap">
</script>
然后我就停在这里了。InfoWindow中显示的代码调用的是除“locations”之外的其他对象。尝试得越多,结果越糟糕...
我想给每个标记添加简单的信息:仅标题和每个标记的唯一网址。
有人可以帮忙吗?