Created
August 27, 2013 20:29
-
-
Save mustardBees/6358741 to your computer and use it in GitHub Desktop.
JavaScript to display our map. Loop through list items, add markers to map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function( $ ) { | |
$( document ).ready( function() { | |
var myMapOptions = { | |
zoom: 15, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map( document.getElementById( 'store-locations-map' ), myMapOptions ); | |
var markerBounds = new google.maps.LatLngBounds(); | |
// Loop though each list item and add marker to map | |
$( '#stores li' ).each( function() { | |
var location = { | |
latLng: new google.maps.LatLng( | |
$( this ).data( 'latitude' ), | |
$( this ).data( 'longitude' ) | |
), | |
title: $( this ).find( 'h2' ).html() | |
}; | |
new google.maps.Marker( { | |
map: map, | |
position: location.latLng, | |
title: location.title | |
} ); | |
markerBounds.extend( location.latLng ); | |
} ); | |
// Set the viewport to contain our markers | |
map.fitBounds( markerBounds ); | |
} ); | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment