<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map"></div>
<!-- this div will hold your store info -->
<div id="info_div"></div>
function initMap() {
var myMapCenter = {lat: 40.785091, lng: -73.968285};
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(document.getElementById('map'), {
center: myMapCenter,
zoom: 14
});
function markStore(storeInfo){
// Create a marker and set its position.
var marker = new google.maps.Marker({
map: map,
position: storeInfo.location,
title: storeInfo.name
});
// show store info when marker is clicked
marker.addListener('click', function(){
showStoreInfo(storeInfo);
});
}
// show store info in text box
function showStoreInfo(storeInfo){
var info_div = document.getElementById('info_div');
info_div.innerHTML = 'Store name: '
+ storeInfo.name
+ '<br>Hours: ' + storeInfo.hours;
}
var stores = [
{
name: 'Store 1',
location: {lat: 40.785091, lng: -73.968285},
hours: '8AM to 10PM'
},
{
name: 'Store 2',
location: {lat: 40.790091, lng: -73.968285},
hours: '9AM to 9PM'
}
];
stores.forEach(function(store){
markStore(store);
});
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.