I am developing a map that will put pins to prevent overflowing the pins, but I wanted to create infoWindow that will display the entire marker, when I click on the marker, I tried to get some help and found out that I can do this with marker.getTitle () but that doesnβt help me because I use the makrewithLable object and donβt use the title, my question is: why add a title to the marker or how do I prefer to use the label instead to list them in the info industry. here is a copy of my work.
google.setOnLoadCallback(initialize); var globalMarker = []; var map; function initialize() { var center = new google.maps.LatLng(45.4214, -75.6919); map = new google.maps.Map(document.getElementById('map'), { zoom: 3, center: center, disableDoubleClickZoom: true, mapTypeId: google.maps.MapTypeId.ROADMAP }); var markers = []; var infowindow = new google.maps.InfoWindow(); for(i=0; i<50; i++) { var latLng = new google.maps.LatLng(center.lat() + Math.random() - 0.5, center.lng() + Math.random() - 0.5); //var latLng = new google.maps.LatLng(45.4214, -75.6919) markers[i] = new MarkerWithLabel({ position: latLng, draggable: true, raiseOnDrag: true, map: map, labelContent: "Marker ID = "+i, labelAnchor: new google.maps.Point(30, 0), labelClass: "labels", // the CSS class for the label labelStyle: {opacity: 0.75} }); markers.push(markers); makeDiv(i, 15, "Marker #"); google.maps.event.addListener(markers[i], 'click', function(e) { infowindow.setContent('Marker postion: ' + this.getPosition()); infowindow.open(map, this);}); } var clusterOptions = { zoomOnClick: false } var markerCluster = new MarkerClusterer(map, markers, clusterOptions); globalMarker = markers.slice(); google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) { var content = ''; // Convert lat/long from cluster object to a usable MVCObject var info = new google.maps.MVCObject; info.set('position', cluster.center_); //---- //Get markers var markers = cluster.getMarkers(); var titles = ""; //Get all the titles for(var i = 0; i < markers.length; i++) { titles += markers[i].getTitle() + "\n"; } //---- infowindow.close(); infowindow.setContent(titles); //set infowindow content to titles infowindow.open(map, info); }); } function makeDiv(index, zoomLevel, content) { document.getElementById("sidebar").innerHTML += '<div onclick="zoomIn(' + index + ',' + zoomLevel + ')">' + content + ' ' + index + '</div>'; } function zoomIn(index, zoomLevel) { map.setCenter(globalMarker[index].getPosition()); map.setZoom(zoomLevel); } google.maps.event.addDomListener(window, 'load', initialize);
thanks
source share