我在我的網站使用谷歌地圖,我想通過使用谷歌羣集處理地圖上的多標記。我已閱讀文檔並按照步驟操作,但是向腳本添加新集羣時未加載映射。谷歌地圖羣集 - Javascript
我是新來的谷歌地圖API,我想添加羣集功能到我的網站。感謝您的任何幫助。
function initMainMap() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
zoom:5,
scrollwheel: false,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
// Display a map on the page
map = new google.maps.Map(document.getElementById("main-map"), mapOptions);
map.setTilt(45);
// Multiple Markers
var markers = [
['Test, Test', 33.890396,35.506160],
['Test, Test', 33.880007,35.514207],
['Test, Test', 33.880007,35.518207],
['Berytech Al Mathaf, Beirut', 33.880307,35.514507],
['Berytech Al Mathaf, Beirut', 33.880407,35.516607]
];
// Info Window Content
var infoWindowContent = [
['<div class="info_content">' +
'<h3>Test</h3>' +
'<p>Test</p>' + '</div>'],
['<div class="info_content">' +
'<h3>Test</h3>' +
'<p>Test</p>' +
'</div>']
];
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(), marker, i;
// Loop through our array of markers & place each one on the map
for(i = 0; i < markers.length; i++) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
// Call the resize function for a responsive container
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(14);
google.maps.event.removeListener(boundsListener);
});
}
有沒有在你的瀏覽器開發者工具控制檯任何錯誤? –
沒有一切正常工作 –
除了沒有地圖? –