function initialize() { var myOptions = { zoom: 15, center: new google.maps.LatLng(-36.87673, 174.77862), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU } } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); setMarkers(map, places); } /** * Data for the markers consisting of a name, a LatLng and a zIndex for * the order in which these markers should display on top of each * other. */ var places = [{"title":"eCard Solutions","lat":"-36.87673","long":"174.77862","z-index":"1","address":"Level 2, 17 Great South Road, Newmarket. Auckland"}] function setMarkers(map, locations) { // Add markers to the map // Marker sizes are expressed as a Size of X,Y // where the origin of the image (0,0) is located // in the top left of the image. // Origins, anchor positions and coordinates of the marker // increase in the X direction to the right and in // the Y direction down. var image = new google.maps.MarkerImage('https://www.ecardsolutions.co.nz/wp-content/plugins/g_maps/images/google-ecard-sml.png', // This marker is 32 pixels wide by 32 pixels tall. new google.maps.Size(32, 32), // The origin for this image is 0,0. new google.maps.Point(0,0), // The anchor for this image is the base of the flagpole at 0,32. new google.maps.Point(0, 32)); var shadow = new google.maps.MarkerImage('https://www.ecardsolutions.co.nz/g_maps/wp-content/plugins/g_maps/images/google-truck-shadow-sml.png', // The shadow image is larger in the horizontal dimension // while the position and offset are the same as for the main image. new google.maps.Size(37, 32), new google.maps.Point(0,0), new google.maps.Point(0, 32)); // Shapes define the clickable region of the icon. // The type defines an HTML <area> element 'poly' which // traces out a polygon as a series of X,Y points. The final // coordinate closes the poly by connecting to the first // coordinate. var shape = { coord: [1, 1, 1, 32, 32, 32, 32 , 1], type: 'poly' }; var infowindow; for (var i = 0; i < locations.length; i++) { var place = locations[i]; var myLatLng = new google.maps.LatLng(Number(place["lat"]), Number(place["long"])); var marker = new google.maps.Marker({ position: myLatLng, map: map, shadow: shadow, icon: image, shape: shape, title: place["title"], zIndex: Number(place["z-index"]) }); (function(i, marker) { var place = locations[i]; var content = '
' + '' + '

'+ place["title"] +'

' + '

'+ place["address"] +'

' + '
'; // Creating the event listener. It now has access to the values of // i and marker as they were during its creation google.maps.event.addListener(marker, 'click', function() { if (!infowindow) { infowindow = new google.maps.InfoWindow(); } // Setting the content of the InfoWindow infowindow.setContent(content); // Tying the InfoWindow to the marker infowindow.open(map, marker); }); })(i, marker); } } jQuery(document).ready( function($){ initialize(); });