所以基本上我想要做的是有一個地圖集羣,一旦你點擊進入集羣並點擊個人地圖標記,你將鏈接到不同的頁面在我的網站上。在標記集羣中添加地圖標記的URL谷歌地圖API
這是我到目前爲止。但我似乎不能通過..拉到不同的標記URLS。
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {lat: -39.3642, lng: 164.0444318}
});
// 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,
url: "http://travelpark.co.nz" //Will be different for each marker
});
});
// 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: -37.7862985, lng: 175.2773836},
{lat: -37.8011434, lng: 174.871265}
]
google.maps.event.addListener(markers, 'click', function() {
window.location.href = this.url;
});
在底部的事件監聽器不工作..我似乎無法弄清楚這一點。任何幫助將不勝感激
您試圖分配偵聽器數組。使用foreach分別指定該數組中的每個標記對象。 – dev8080