So I'm making a real estate website, and the client has asked that all properties can be viewed on a map. I thought the best way to do this to avoid it looking too cluttered would be to use Marker Clusters. However, I need each individual marker to link to that specific properties page. I'm not too experienced with Javascript so I'm struggling to crack this one.
Right now, the map is completely unresponsive (You cant move or zoom the map) and no markers are displayed.
This is my code so far, where am I going wrong?
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: {<?php echo convertAddressToLngLat('Hastings, East Sussex');?>}
});
var markers = locations.map(function(link, location, i) {
var marker = new google.maps.Marker({
position: location,
url: link //Will be different for each marker
});
google.maps.event.addListener(marker, 'click', function(){
window.location.href = this.url;
});
return 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 = [
["www.google.com", {lat: 50.8542590, lng: 0.5734530}],
]
</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?key=AIzaSyDlrUspRmip7Verfu7IDtW-FYkkum1QZMs&callback=initMap"></script>