dylanmcleod
7/23/2015 - 2:03 AM

Multiple Map Markers - Add script to Page Names & Upload map-marker.png to root http://www.orientalrugspa.com.au/contact.html

Multiple Map Markers - Add script to Page Names & Upload map-marker.png to root http://www.orientalrugspa.com.au/contact.html

<script>
jQuery(function($) {
    // Asynchronously Load the map API 
    var script = document.createElement('script');
    script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
    document.body.appendChild(script);
});

function initialize() {
    var map;
    var bounds = new google.maps.LatLngBounds();
    var mapOptions = {
        mapTypeId: 'roadmap'
    };
                    
    // Display a map on the page
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    map.setTilt(45);
        
    // Multiple Markers
    var markers = [
        ['Tullamarine', -37.702206, 144.887895],
        ['Lilydale', -37.749654, 145.350770],
        ['Carrum Downs', -38.105892, 145.166155]
    ];

    var icons = ["map-marker.png", "map-marker2.png", "map-marker3.png"];
var image = 'map-icon.png'
                        
    // Info Window Content
    var infoWindowContent = [
        ['<div class="info_content">' +
        '<h3>Tullamarine</h3>' +
        '<p>Suite 1/21 Lindaway Pl, Tullamarine, VIC 3043</p>' +
        '<B>Phone:</b> 1800 75 31 30 <BR>' +
        '<b>Email:</b> <a href="mailTo:tullamarine@orientalrugspa.com.au">tullamarine@orientalrugspa.com.au</a> </b><BR>' +
        '</div>'],
        ['<div class="info_content">' +
        '<h3>Lilydale</h3>' +
        '<p>Suite 7/157-161 Beresford Rd, Lilydale, VIC 3140</p>' +
        '<B>Phone:</b> 1800 787 184<BR>' +
        '<b>Email:</b> <a href="mailTo:lilydale@orientalrugspa.com.au">lilydale@orientalrugspa.com.au</a> </b><BR>' +
        '</div>'],
        ['<div class="info_content">' +
        '<h3>Carrum Downs</h3>' +
        '<p>Suite 3/1-5 Amayla Cres, Carrum Downs, VIC 3201</p>' +
        '<B>Phone:</b> 1300 773 726<BR>' +
        '<b>Email:</b> <a href="mailTo:carrumdowns@orientalrugspa.com.au">carrumdowns@orientalrugspa.com.au</a> </b><BR>' +
        '</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],
            icon: icons[i]
        });
        
        // 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);
    }

    // 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(8);
        google.maps.event.removeListener(boundsListener);
    });
    
}


</script>
<div class="map_canvas">&nbsp;</div>

<style>
#map_canvas {
    width: 100%;
/*  height: 100%; */
    height:400px;
}

.info_content {
  min-width:230px;
}
</style>